用户登录
用户注册

分享至

浅谈Angular4实现热加载开发旅程

  • 作者: 爱上猫的诱惑
  • 来源: 51数据库
  • 2021-09-03

本文介绍了angular4实现热加载开发,分享给大家,具体如下:

安装插件

npm install @angularclass/hmr -d

配置插件

 // main.ts
if (environment.production) {
 enableprodmode();
}else {
 if (module.hot) {
  module.hot.accept();
  module.hot.dispose(() => {
   let _styles = document.head.queryselectorall('style');
   let styles = array.prototype.slice.call(_styles);
   styles
    .filter((style: any) => style.innertext.indexof('_ng') !== -1)
    .map((el: any) => document.head.removechild(el));
  })
 }
}

platformbrowserdynamic().bootstrapmodule(appmodule);

配置typescript

// typings.d.ts
declare var module: nodemodule;
interface nodemodule {
 hot: any;
}

启用热加载

// package.json
ng serve -h d.io --port 3000 --hmr --proxy-config=./proxy.json

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

软件
前端设计
程序设计
Java相关