通过在Laravel Mix内部的Extract.js组件中插入console.log,我发现在当前设置下,插件只是将这些行插入Webpack配置的优化字段中。
optimization: {
runtimeChunk: { name: '/js/manifest' },splitChunks: {
cacheGroups: {},chunks: 'all',name: '/js/vendor',},
为了过滤供应商文件中的内容,我必须像这样编辑splitChunks:
splitChunks: {
cacheGroups: {
vendor: {
// moved name and chunks here
name: 'js/vendor',// you can pass a RegExp to test,but also a function
test(module/*,chunk */) {
if (module.context) {
// node_modules are needed
const isNodeModule = module.context.includes('node_modules');
// but only specific node_modules
const nodesToBundle = [
'vue','lodash','axios',].some(str => module.context.includes(str));
if (isNodeModule && nodesToBundle) {
return true;
}
}
return false;
},}
},// removed name and chunks from here
// chunks: 'all',// name: '/js/vendor',
这些更改之后,我仍然对您遇到的名字感到奇怪,但是由于这个GitHub repo,我发现我可以通过添加以下内容来消除此行为:
default: false,// disable default groups
vendors: false,// disable vendors group
到“ CacheGroups”字段。
所以我完整的webpackConfig函数参数是:
.webpackConfig({
output: {
// with other settings
},optimization: {
runtimeChunk: { name: '/js/manifest' },splitChunks: {
cacheGroups: {
default: false,vendors: false,vendor: {
name: 'js/vendor',but also a function
test(module/*,chunk */) {
if (module.context) {
// node_modules are needed
const isNodeModule = module.context.includes('node_modules');
// but only specific node_modules
const nodesToBundle = [
'vue',].some(str => module.context.includes(str));
if (isNodeModule && nodesToBundle) {
return true;
}
}
return false;
},}
},}
})
确保还删除混合文件中的extract()调用。
本文链接:https://www.f2er.com/2057833.html