Skip to content

Commit 06eed40

Browse files
committed
fix: split for lib
1 parent b968cdd commit 06eed40

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

lib/optimize.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,28 @@ module.exports = class WebpackOptimize {
2727
getCacheVendors() {
2828
const { lib } = this.ctx.config;
2929
const strRegex = Array.isArray(lib) ? lib.join('|') : '.*';
30-
const test = new RegExp(`node_modules/(${strRegex})\\.js`);
31-
return {
32-
name: 'common',
30+
const test = new RegExp(`node_modules/_?(${strRegex})(@|/)`);
31+
const options = lib ? {
32+
chunks: 'all',
33+
minChunks: 1
34+
} : {
3335
chunks: 'initial',
34-
minChunks: 2,
35-
test
36+
minChunks: 2
3637
};
38+
return this.ctx.merge(options, {
39+
name: 'common',
40+
test
41+
});
3742
}
3843

3944
getCacheStyles() {
4045
return {
4146
name: 'common',
4247
chunks: 'initial',
4348
minChunks: 2,
44-
test: /\.(css|less|scss|stylus)$/
49+
test: /\.(css|less|scss|stylus)$/,
50+
enforce: true,
51+
priority: 50
4552
};
4653
}
4754

@@ -94,10 +101,10 @@ module.exports = class WebpackOptimize {
94101
splitChunks: {
95102
chunks: 'initial',
96103
minSize: 30000,
97-
maxAsyncRequests: 5,
98-
maxInitialRequests: 3,
104+
minChunks: 1,
99105
name: false,
100106
cacheGroups: {
107+
default: false,
101108
vendors: this.getCacheVendors(),
102109
styles: this.getCacheStyles()
103110
}

0 commit comments

Comments
 (0)