Node.js/webpack/SplitChunksPlugin:修订间差异
来自康健生活
创建页面,内容为“== 引言 == <syntaxhighlight lang="javascript"> optimization: { splitChunks: { chunks: "initial", // 代码块类型 必须三选一: "initial"…” |
|||
| 第23行: | 第23行: | ||
} | } | ||
}</syntaxhighlight> | }</syntaxhighlight> | ||
{{unknown| | {{unknown|寻找蓝海96}} | ||
拆包 | |||
<syntaxhighlight lang="javascript"> | |||
cacheGroups: { | |||
reactBase: { | |||
name: 'reactBase', | |||
test: (module) => { | |||
return /react|redux/.test(module.context); | |||
}, | |||
chunks: 'initial', | |||
priority: 10, | |||
}, | |||
utilBase: { | |||
name: 'utilBase', | |||
test: (module) => { | |||
return /rxjs|lodash/.test(module.context); | |||
}, | |||
chunks: 'initial', | |||
priority: 9, | |||
}, | |||
uiBase: { | |||
name: 'chartBase', | |||
test: (module) => { | |||
return /echarts/.test(module.context); | |||
}, | |||
chunks: 'initial', | |||
priority: 8, | |||
}, | |||
commons: { | |||
name: 'common', | |||
chunks: 'initial', | |||
priority: 2, | |||
minChunks: 2, | |||
}, | |||
}</syntaxhighlight> | |||
2020年6月24日 (三) 07:56的最新版本
引言
optimization: {
splitChunks: {
chunks: "initial", // 代码块类型 必须三选一: "initial"(初始化) | "all"(默认就是all) | "async"(动态加载)
minSize: 0, // 最小尺寸,默认0
minChunks: 1, // 最小 chunk ,默认1
maxAsyncRequests: 1, // 最大异步请求数, 默认1
maxInitialRequests: 1, // 最大初始化请求书,默认1
name: () => {}, // 名称,此选项课接收 function
cacheGroups: { // 缓存组会继承splitChunks的配置,但是test、priorty和reuseExistingChunk只能用于配置缓存组。
priority: "0", // 缓存组优先级,即权重 false | object |
vendor: { // key 为entry中定义的 入口名称
chunks: "initial", // 必须三选一: "initial"(初始化) | "all" | "async"(默认就是异步)
test: /react|lodash/, // 正则规则验证,如果符合就提取 chunk
name: "vendor", // 要缓存的 分隔出来的 chunk 名称
minSize: 0,
minChunks: 1,
enforce: true,
reuseExistingChunk: true // 可设置是否重用已用chunk 不再创建新的chunk
}
}
}
}
(来源摘自互联网示例,作者 寻找蓝海96)
拆包
cacheGroups: {
reactBase: {
name: 'reactBase',
test: (module) => {
return /react|redux/.test(module.context);
},
chunks: 'initial',
priority: 10,
},
utilBase: {
name: 'utilBase',
test: (module) => {
return /rxjs|lodash/.test(module.context);
},
chunks: 'initial',
priority: 9,
},
uiBase: {
name: 'chartBase',
test: (module) => {
return /echarts/.test(module.context);
},
chunks: 'initial',
priority: 8,
},
commons: {
name: 'common',
chunks: 'initial',
priority: 2,
minChunks: 2,
},
}
No categories