在webpack配置中具有多个入口点,例如:
entry: {
home: './resources/assets/scripts/sections/home/home.bundle.js',
calc: './resources/assets/scripts/sections/calc/calc.bundle.js',
(...)
}
以及splitChunks的优化,例如:
optimization: {
splitChunks: {
chunks: "all",
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
priority: -10
},
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
}
}
}
},
并使用HtmlWebPackPlugin,例如:
new HtmlWebPackPlugin({
template: "./resources/views/pages/app/sub-pages/home.blade.template.php",
filename: "../../resources/views/pages/app/sub-pages/home.blade.php",
inject: true,
chunks: ['home'] // <--- what should be going here?
}),
new HtmlWebPackPlugin({
template: "./resources/views/pages/app/sub-pages/calc.blade.template.php",
filename: "../../resources/views/pages/app/sub-pages/calc.blade.php",
inject: true,
chunks: ['calc'] // <--- what should be going here?
}),
HtmlWebPackPlugin仅向home
注入1 home.blade.php
块,向calc
文件注入1 calc.blade.php
块,而忽略其他文件。
但是... webpack会生成更多文件,例如:
vendors~home~calc.js
vendors~calc.js
vendors~home.js
(...)
我尝试过的是在htmlWebPackPlugin配置中省略任何chunks
,但是随后所有文件都被注入,因此vendors~cals
在home.blade.php
中,等等...这是错误的
如何配置插件以仅使用其中包含home
或calc
的文件(块)?