更改文件后如何重新编译webpack? [英] How to recompile webpack after changing files?
问题描述
我正在使用带有两个入口点的 webpack:
I'm using webpack with two entry points:
entry: {
js: './assets/index.js',
css: './assets/sass/all.scss'
},
我想配置它,以便当我更改 js
或 scss
文件时,它会自动再次运行 webpack.
I want to configure it so when I change a js
or scss
file it automatically run webpack again.
我尝试将 webpack-dev-server
与命令一起使用:
I tried to use webpack-dev-server
with the command:
webpack-dev-server --hot
看起来它又在构建了,它输出消息
It looks like it is building again, it outputs the message
webpack:捆绑包现在有效.
webpack: bundle is now VALID.
但是,如果我尝试刷新浏览器,则看不到我的更改.(在开发工具上禁用缓存并按下 Ctrl+F5).重新启动节点也不起作用,就好像它在其他地方构建而不是在配置的输出文件上:
However if I try to refresh the browser I can't see my changes. (Cache disabled on dev tools and Ctrl+F5 pressed). Restarting node also doesn't work, it is as if it had build somewhere else and not on the configured output file:
output: {
path: path.join(__dirname, '/public'),
filename: 'bundle.js'
},
推荐答案
如果您希望 webpack 监视更改,只需使用 watch
标志:
If you want webpack to watch for changes simply use the watch
flag:
webpack --watch
有了这个选项,webpack 将监视更改并重新编译.
With this option webpack will watch for changes and re-compile.
这篇关于更改文件后如何重新编译webpack?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!