[英]Webpack-dev-server doesn't build files on change
So I have the following webpack configuration : 所以我有以下webpack配置:
import path from 'path';
module.exports = {
entry: {
index: './dev/index.js'
},
output: {
path: path.join(__dirname, 'dist'),
publicPath: './dist/',
filename: 'bundle.js',
chunkFilename: '[id].bundle.js'
},
module:{
loader:{
test: /\.js$/,
exclude:path.resolve(__dirname, "node_modules"),
loader: 'js'
}
}
};
The problem is that when I do webpack --watch
the file does build in the /dist/
folder at every change. 问题是,当我做webpack --watch
,文件会在每次更改时都在/dist/
文件夹中构建。 Yet when I run the webpack-dev-server
the files don't even build. 然而,当我运行webpack-dev-server
,文件甚至无法构建。 Why is that? 这是为什么?
Please help. 请帮忙。
The reason you are not seeing files emitted into your dist folder is because webpack-dev-server uses an in-memory filesystem 您没有看到文件发送到dist文件夹的原因是因为webpack-dev-server使用内存中的文件系统
This allows for extremely fast incremental builds when your code changes. 这可以在代码更改时实现极快的增量构建。 This was an intentional design on our part. 这是我们的故意设计。 You can view the resulting code in your browser and never need to reference those files. 您可以在浏览器中查看生成的代码,而不需要引用这些文件。
It is not recommended by us, for the sake of build performance, but you can look in to plugins like write-file-webpack-plugin if you need this feature. 我们不建议为了构建性能,但如果需要此功能,可以查看write-file-webpack-plugin等插件 。
'webpack' writes your bundle to disk, whereas 'webpack-dev-server' loads the bundle into memory. 'webpack'将你的包写入磁盘,而'webpack-dev-server'将包装入内存。 So when running the latter command you wont see a new 'bundle.js' file appear in your file system, even though you should see output to the console reporting the bundling and the start up of the dev server). 因此,当运行后一个命令时,您将看不到新的“bundle.js”文件出现在您的文件系统中,即使您应该看到输出到控制台报告捆绑和启动服务器的启动。
The output.publicPath config key determines the location of the in-memory bundle on the host dev server. output.publicPath配置密钥确定主机dev服务器上的内存中软件包的位置。 So if you set the publicPath to 'dist' then the index.html served by the webpack dev server will need a script tag in order to reference the bundle. 因此,如果将publicPath设置为'dist',那么webpack dev服务器所服务的index.html将需要一个脚本标记才能引用该bundle。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.