[英]Webpack, optimization chunking gives “Conflict: Multiple chunks emit assets to the same filename” error
Info信息
I am trying to generate my own webpack config and have some problems getting it working.我正在尝试生成自己的 webpack 配置并且在使其正常工作时遇到了一些问题。
Problem问题
When trying to use optimization to split files into chunks I get the a error like underneath当尝试使用优化将文件拆分为块时,我收到如下错误
Error: Conflict: Multiple chunks emit assets to the same filename static/js/bundle.js (chunks main and vendors-node_modules_react-hot-loader_patch_js-node_modules_react_jsx-dev-runtime_js-node_mod-4610d2)
错误:冲突:多个块将资产发送到相同的文件名 static/js/bundle.js(块 main 和 vendor-node_modules_react-hot-loader_patch_js-node_modules_react_jsx-dev-runtime_js-node_mod-4610d2)
If I remove the optimization section it works but without chunking.如果我删除优化部分,它可以工作但没有分块。 I have looked to the create react app webpack.config.js to get something to reference while generating this.
我查看了创建反应应用程序webpack.config.js以在生成此内容时获得一些参考。
As you can see they have the optimization section working with chunking in both development and production.正如您所看到的,他们的优化部分在开发和生产中都使用了分块。 Why do I get the conflict error when using it?
为什么我在使用时会出现冲突错误?
Code代码
Minified/simplified version of my config (runtimeChunk disabled, as it also gives the same conflict error)我的配置的缩小/简化版本(runtimeChunk 已禁用,因为它也给出了相同的冲突错误)
webpack.config.js webpack.config.js
module.exports = () => {
process.env.NODE_ENV = "development";
process.env.BABEL_ENV = "development";
return {
mode: "development",
entry: ["react-hot-loader/patch", "./src"],
output: {
path: undefined,
publicPath: "/",
filename: "static/js/bundle.js",
chunkFilename: "static/js/[name].chunk.js",
},
optimization: {
minimize: false,
splitChunks: {
chunks: "all",
name: false
},
// runtimeChunk: {
// name: (entrypoint) => `runtime-${entrypoint.name}`,
// },
},
resolve: {
modules: [path.join(__dirname, "src"), "node_modules"],
alias: {
"react-dom": "@hot-loader/react-dom",
},
},
module: {
rules: [
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: path.resolve(__dirname, "./src"),
exclude: /node_modules/,
use: ["babel-loader"],
},
],
},
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.resolve(__dirname, "./public/index.html"),
}),
new webpack.HotModuleReplacementPlugin(),
],
devServer: {
compress: true,
hot: true,
contentBase: "./build",
historyApiFallback: true,
},
devtool: "inline-source-map",
};
};
.babelrc .babelrc
{"presets": [["react-app", {"runtime": "automatic"}]]}
Got it to work had to change filename: "static/js/bundle.js"
to filename: "static/js/[name].js"
让它工作必须将
filename: "static/js/bundle.js"
更改为filename: "static/js/[name].js"
output: {
path: undefined,
publicPath: "/",
filename: "static/js/[name].js",
chunkFilename: "static/js/[name].chunk.js",
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.