webpack“–watch”vs“–hot”:有什么区别?

根据webpack文档@ https://webpack.github.io/docs/tutorials/getting-started/#watch-mode

When using watch mode, webpack installs file watchers to all files,
which were used in the compilation process. If any change is detected,
it’ll run the compilation again. When caching is enabled, webpack
keeps each module in memory and will reuse it if it isn’t changed.

所以,基本上,运行webpack和webpack –watch之间的区别在于,在使用–watch时,你的CLI会在编译过程中挂起,等待文件中的任何代码更改,如果有更改,那么它将重新编译,再等一下您应该知道,如果您使用的是webpack-dev-server,那么您不需要使用此选项,因为默认情况下webpack-dev-server根据其文档使用webpack的监视模式:

The dev server uses webpack’s watch mode. It also prevents webpack
from emitting the resulting files to disk. Instead it keeps and serves
the resulting files from memory.

那么,什么是webpack-dev-server –hot?基本上,这会将HotModuleReplacementPlugin添加到webpack配置中,这实际上只允许您重新加载已更改的组件,而不是执行整页刷新!在与州合作时非常有用!根据文件:

Each mode also supports Hot Module Replacement in which the bundle is
notified that a change happened instead of a full page reload. A Hot
Module Replacement runtime could then load the updated modules and
inject them into the running app.

有关它是什么以及如何使用它的更多信息:https://webpack.github.io/docs/webpack-dev-server.html#hot-module-replacement

我希望这有助于更多地理解webpack!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值