Laravel Mix 内の Extract.js コンポーネントに console.log を挿入すると、現在の設定では、プラグインがこれらの行を Webpack 構成の最適化フィールドに挿入しているだけであることがわかりました。
optimization: {
runtimeChunk: { name: '/js/manifest' },
splitChunks: {
cacheGroups: {},
chunks: 'all',
name: '/js/vendor',
},
},
vendor ファイル内で何が起こっているかをフィルタリングするために、次のように splitChunks を編集する必要がありました。
splitChunks: {
cacheGroups: {
vendor: {
// moved name and chunks here
name: 'js/vendor',
chunks: 'all',
// 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 リポジトリのおかげで、次を追加することでこの動作を削除できることがわかりました:
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',
chunks: 'all',
// 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;
},
}
},
},
}
})
mix ファイルの extract() 呼び出しも必ず削除してください。