Skip to content

Commit e9ac46d

Browse files
committed
normalize options for commons chunk plugin
1 parent 4369dfa commit e9ac46d

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

lib/optimize/CommonsChunkPlugin.js

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,45 @@ The available options are:
2424
minSize: number`);
2525
}
2626

27-
if(Array.isArray(options) || typeof options === "string") {
28-
options = {
29-
name: options
27+
const normalizedOptions = this.normalizeOptions(options);
28+
29+
this.chunkNames = normalizedOptions.chunkNames;
30+
this.filenameTemplate = this.filenameTemplate;
31+
this.minChunks = normalizedOptions.minChunks;
32+
this.selectedChunks = normalizedOptions.selectedChunks;
33+
this.async = normalizedOptions.async;
34+
this.minSize = normalizedOptions.minSize;
35+
this.ident = normalizedOptions.ident;
36+
}
37+
38+
normalizeOptions(options) {
39+
if(Array.isArray(options)) {
40+
return {
41+
chunkNames: options,
42+
};
43+
}
44+
45+
if(typeof options === "string") {
46+
return {
47+
chunkNames: [options],
3048
};
3149
}
32-
this.chunkNames = options.name || options.names;
33-
this.filenameTemplate = options.filename;
34-
this.minChunks = options.minChunks;
35-
this.selectedChunks = options.chunks;
36-
if(options.children) this.selectedChunks = false;
37-
this.async = options.async;
38-
this.minSize = options.minSize;
39-
this.ident = __filename + (nextIdent++);
50+
51+
// if "children" is set, set selectedChunks to false instead of specified chunks
52+
// TODO: why? :P
53+
const selectedChunks = options.children ? false : options.chunks;
54+
const chunkNames = options.name ? [options.name] : options.names;
55+
return {
56+
chunkNames: chunkNames,
57+
filenameTemplate: options.filename,
58+
minChunks: options.minChunks,
59+
selectedChunks: selectedChunks,
60+
async: options.async,
61+
minSize: options.minSize,
62+
ident: __filename + (nextIdent++),
63+
};
4064
}
65+
4166
apply(compiler) {
4267
const chunkNames = this.chunkNames;
4368
const filenameTemplate = this.filenameTemplate;

0 commit comments

Comments
 (0)