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

 围脖上的博博_771 发布于 2022-11-12 13:47

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?

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

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

    2022-11-12 13:47 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有