首页 > webpack中hot module replacement官方文档一段话的理解问题?

webpack中hot module replacement官方文档一段话的理解问题?

webpack官方wiki里的一段关于工作原理的话:

Webpacks adds a small HMR runtime to the bundle, during the build process, that runs inside your app. When the build completes, Webpack does not exit but stays active, watching the source files for changes. If Webpack detects a source file change, it rebuilds only the changed module(s).Depending on the settings, Webpack will either send a signal to the HMR runtime, or the HMR runtime will poll webpack for changes. Either way, the changed module is sent to the HMR runtime which then tries to apply the hot update. First it checks whether the updated module can self-accept. If not, it checks those modules that have required the updated module. If these too do not accept the update, it bubbles up another level, to the modules that required the modules that required the changed module. This bubbling-up will continue until either the update is accepted, or the app entry point is reached, in which case the hot update fails.

其中: First it checks whether the updated module can self-accept.

这里的self-accept是指什么?怎样才能算self-accept?


多一点点耐心,你要是再往后面看看,就看到self-accept是个什么鬼了

说白了,“局部热更新”是需要你自己编写的模块支持的,如果变更的模块没有self-acceptHMR会把变更信号继续冒泡给上一级,由上一级再检查能不能“热更新”,直至最顶层的entry,最后没辙只能hot update fails,对应的结果就是浏览器刷新了一下

【热门文章】
【热门文章】