Skip to content

Commit

Permalink
feat: not need set entry for lib
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Nov 13, 2018
1 parent 06eed40 commit 177ed1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WebpackClientBuilder extends WebpackBaseBuilder {
this.setDevTool(config.devtool);
this.setPack(config.packs);
this.setTarget(WebpackClientBuilder.TARGET);
this.setCommonsChunkLib();
// this.setCommonsChunkLib();
this.setStartCreateQueue(this.setBabelENV);
this.setCreateQueue(this.createDllAssetPlugin);
this.setCreateQueue(this.createDllReferencePlugin);
Expand Down
42 changes: 25 additions & 17 deletions lib/optimize.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = class WebpackOptimize {
constructor(ctx) {
this.ctx = ctx;
this.optimization = ctx.utils.cloneDeep(ctx.config.optimization || {});
this.lib = this.ctx.config.lib;
}

getCommonsChunk() {
Expand All @@ -25,26 +26,33 @@ module.exports = class WebpackOptimize {
}

getCacheVendors() {
const { lib } = this.ctx.config;
const strRegex = Array.isArray(lib) ? lib.join('|') : '.*';
const test = new RegExp(`node_modules/_?(${strRegex})(@|/)`);
const options = lib ? {
const modules = [];
const files = [];
const lib = this.lib || ['.*'];
lib.forEach(m => {
if (/\.(jsx?|tsx?)$/.test(m)) {
files.push(m);
} else {
modules.push(m);
}
});
files.unshift(`node_modules/_?(${modules.join('|')})(@|/)`);
const strRegex = files.join('|');
const test = new RegExp(strRegex);
return {
name: 'common',
chunks: 'all',
minChunks: 1
} : {
chunks: 'initial',
minChunks: 2
minChunks: 1,
test: module => {
return test.test(module.context);
}
};
return this.ctx.merge(options, {
name: 'common',
test
});
}

getCacheStyles() {
return {
name: 'common',
chunks: 'initial',
chunks: 'all',
minChunks: 2,
test: /\.(css|less|scss|stylus)$/,
enforce: true,
Expand Down Expand Up @@ -99,10 +107,10 @@ module.exports = class WebpackOptimize {
name: 'runtime'
},
splitChunks: {
chunks: 'initial',
minSize: 30000,
minChunks: 1,
name: false,
name: true,
chunks: 'all',
minSize: this.lib ? 1 : 10000,
minChunks: this.lib ? 1 : 2,
cacheGroups: {
default: false,
vendors: this.getCacheVendors(),
Expand Down

0 comments on commit 177ed1a

Please sign in to comment.