当前位置: 移动技术网 > IT编程>脚本编程>AngularJs > 浅谈Angular4实现热加载开发旅程

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

本文介绍了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

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网