模块热替换 HMR

时间:2023-03-08 19:50:12

devserver:{hot:true},既及时更新代码,样式(需配合loader)变化,自动重编译,只适用于开发环境。

模块热替换   HMR

入口文件中,添加监视:

+ if (module.hot) {
+ module.hot.accept('./print.js', function() {
+ console.log('Accepting the updated printMe module!');
+ printMe();
+ })
+ }