使用什么有什么区别呢?
webpack --watch
和
webpack-dev-server --hot
谢谢。
使用什么有什么区别呢?
webpack --watch
和
webpack-dev-server --hot
谢谢。
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
是什么呢?基本上,这将在webpack配置中添加HotModuleReplacementPlugin
,这将允许您只重新加载更改的组件,而不是进行完整的页面刷新!当您使用状态时非常有用!根据文档:
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。--watch
意味着:监听文件变化,当源文件发生变化时重新编译。
--hot
(热重载)意味着:当源代码发生更改时,不重新加载整个页面,而只是重新加载更改的部分。
webpack-dev-server
对吗? - Niner