webpack2-lessons icon indicating copy to clipboard operation
webpack2-lessons copied to clipboard

lesson2中的例子并没有实现热更新

Open lisleyang opened this issue 8 years ago • 0 comments

更改的时候,仍然会由webpack-dev-server进行自动刷新,而不是HotModuleReplacePlugin的不刷新。

“要使HMR功能生效,还需要做一件事情,就是要在应用热替换的模块或者根模块里面加入允许热替换的代码。否则,热替换不会生效,还是会重刷整个页面。下面是摘自webpack在github上docs的原话: A module can only be updated if you "accept" it. So you need to module.hot.accept the module in the parents or the parents of the parents... I. e. a Router is a good place or a subview. ” 具体的代码是:

if(module.hot)
    module.hot.accept();

lisleyang avatar Dec 12 '17 06:12 lisleyang