Skip to content

Commit 4960c5b

Browse files
committed
cleanup CommonsChunkPlugins changes
1 parent f5b8225 commit 4960c5b

File tree

15 files changed

+307
-10
lines changed

15 files changed

+307
-10
lines changed

lib/optimize/CommonsChunkPlugin.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ You can however specify the name of the async chunk by passing the desired strin
107107
/**
108108
* These chunks are subject to get "common" modules extracted and moved to the common chunk
109109
*/
110-
const affectedChunks = this.getAffectedChunks(compilation, chunks, targetChunk, targetChunks, idx, this.selectedChunks, this.async, this.children);
110+
const affectedChunks = this.getAffectedChunks(compilation, chunks, targetChunk, targetChunks, idx, this.selectedChunks, this.async, this.children, this.deepChildren);
111111

112112
// bail if no chunk is affected
113113
if(!affectedChunks) {
@@ -214,7 +214,7 @@ You can however specify the name of the async chunk by passing the desired strin
214214
Take a look at the "name"/"names" or async/children option.`);
215215
}
216216

217-
getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption) {
217+
getAffectedUnnamedChunks(affectedChunks, targetChunk, rootChunk, asyncOption, deepChildrenOption) {
218218
let chunks = targetChunk.chunks;
219219
chunks && chunks.forEach((chunk) => {
220220
if(chunk.isInitial()) {
@@ -225,28 +225,28 @@ Take a look at the "name"/"names" or async/children option.`);
225225
// b) themselves affected chunks
226226
// we can assume that this chunk is an affected chunk too, as there is no way a chunk that
227227
// isn't only depending on the target chunk is a parent of the chunk tested
228-
if(asyncOption || chunk.parents.every((parentChunk) => parentChunk === targetChunk || affectedChunks.has(parentChunk))) {
228+
if(asyncOption || chunk.parents.every((parentChunk) => parentChunk === rootChunk || affectedChunks.has(parentChunk))) {
229229
// This check not only dedupes the affectedChunks but also guarantees we avoid endless loops
230-
if(!affectedChunks.has(chunk) || affectedChunks.values().next().value === chunk) {
230+
if(!affectedChunks.has(chunk)) {
231231
// We mutate the affected chunks before going deeper, so the deeper levels and other branches
232-
// Have the information of this chunk being affected for their assertion if a chunk should
232+
// have the information of this chunk being affected for their assertion if a chunk should
233233
// not be affected
234234
affectedChunks.add(chunk);
235235

236236
// We recurse down to all the children of the chunk, applying the same assumption.
237237
// This guarantees that if a chunk should be an affected chunk,
238238
// at the latest the last connection to the same chunk meets the
239239
// condition to add it to the affected chunks.
240-
if(this.deepChildren === true) {
241-
this.getAffectedUnnamedChunks(affectedChunks, chunk, asyncOption);
240+
if(deepChildrenOption === true) {
241+
this.getAffectedUnnamedChunks(affectedChunks, chunk, rootChunk, asyncOption, deepChildrenOption);
242242
}
243243
}
244244
}
245245
});
246246
}
247247

248-
getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, children) {
249-
const asyncOrNoSelectedChunk = children || asyncOption;
248+
getAffectedChunks(compilation, allChunks, targetChunk, targetChunks, currentIndex, selectedChunks, asyncOption, childrenOption, deepChildrenOption) {
249+
const asyncOrNoSelectedChunk = childrenOption || asyncOption;
250250

251251
if(Array.isArray(selectedChunks)) {
252252
return allChunks.filter(chunk => {
@@ -258,7 +258,7 @@ Take a look at the "name"/"names" or async/children option.`);
258258

259259
if(asyncOrNoSelectedChunk) {
260260
let affectedChunks = new Set();
261-
this.getAffectedUnnamedChunks(affectedChunks, targetChunk, asyncOption);
261+
this.getAffectedUnnamedChunks(affectedChunks, targetChunk, targetChunk, asyncOption, deepChildrenOption);
262262
return Array.from(affectedChunks);
263263
}
264264

test/statsCases/commons-chunk-plugin-children/a.js

Whitespace-only changes.

test/statsCases/commons-chunk-plugin-children/b.js

Whitespace-only changes.

test/statsCases/commons-chunk-plugin-children/c.js

Whitespace-only changes.

test/statsCases/commons-chunk-plugin-children/d.js

Whitespace-only changes.

test/statsCases/commons-chunk-plugin-children/e.js

Whitespace-only changes.

test/statsCases/commons-chunk-plugin-children/expected.txt

Lines changed: 208 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import(/* webpackChunkName: "x1" */"./x1");
2+
import(/* webpackChunkName: "x2" */"./x2");
3+
import(/* webpackChunkName: "x3" */"./x3");
4+
import(/* webpackChunkName: "x4" */"./x4");
5+
import(/* webpackChunkName: "x5" */"./x5");
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"use strict";
2+
3+
const webpack = require("../../../");
4+
const basic = {
5+
entry: {
6+
main: "./index"
7+
},
8+
output: {
9+
filename: "bundle.js"
10+
},
11+
stats: {
12+
hash: false,
13+
timings: false,
14+
chunks: true,
15+
chunkModules: true,
16+
chunkOrigins: true,
17+
modules: false
18+
}
19+
};
20+
module.exports = [
21+
Object.assign({
22+
name: "normal"
23+
}, basic),
24+
Object.assign({
25+
name: "children",
26+
plugins: [
27+
new webpack.optimize.CommonsChunkPlugin({
28+
name: "main",
29+
children: true,
30+
minChunks: 3
31+
})
32+
]
33+
}, basic),
34+
Object.assign({
35+
name: "async",
36+
plugins: [
37+
new webpack.optimize.CommonsChunkPlugin({
38+
name: "main",
39+
children: true,
40+
async: true,
41+
minChunks: 3
42+
})
43+
]
44+
}, basic),
45+
Object.assign({
46+
name: "deep-children",
47+
plugins: [
48+
new webpack.optimize.CommonsChunkPlugin({
49+
name: "main",
50+
children: true,
51+
deepChildren: true,
52+
minChunks: 3
53+
})
54+
]
55+
}, basic),
56+
Object.assign({
57+
name: "deep-async",
58+
plugins: [
59+
new webpack.optimize.CommonsChunkPlugin({
60+
name: "main",
61+
children: true,
62+
deepChildren: true,
63+
async: true,
64+
minChunks: 3
65+
})
66+
]
67+
}, basic),
68+
];
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "./a";

0 commit comments

Comments
 (0)