Skip to content

Commit

Permalink
fix: split for lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Nov 13, 2018
1 parent b968cdd commit 06eed40
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@ module.exports = class WebpackOptimize {
getCacheVendors() {
const { lib } = this.ctx.config;
const strRegex = Array.isArray(lib) ? lib.join('|') : '.*';
const test = new RegExp(`node_modules/(${strRegex})\\.js`);
return {
name: 'common',
const test = new RegExp(`node_modules/_?(${strRegex})(@|/)`);
const options = lib ? {
chunks: 'all',
minChunks: 1
} : {
chunks: 'initial',
minChunks: 2,
test
minChunks: 2
};
return this.ctx.merge(options, {
name: 'common',
test
});
}

getCacheStyles() {
return {
name: 'common',
chunks: 'initial',
minChunks: 2,
test: /\.(css|less|scss|stylus)$/
test: /\.(css|less|scss|stylus)$/,
enforce: true,
priority: 50
};
}

Expand Down Expand Up @@ -94,10 +101,10 @@ module.exports = class WebpackOptimize {
splitChunks: {
chunks: 'initial',
minSize: 30000,
maxAsyncRequests: 5,
maxInitialRequests: 3,
minChunks: 1,
name: false,
cacheGroups: {
default: false,
vendors: this.getCacheVendors(),
styles: this.getCacheStyles()
}
Expand Down

0 comments on commit 06eed40

Please sign in to comment.