根据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!