Skip to content

Commit fabd1ab

Browse files
committed
improvements from review by @ooflorent
1 parent 18ae73d commit fabd1ab

File tree

19 files changed

+245
-20
lines changed

19 files changed

+245
-20
lines changed

lib/Chunk.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,12 @@ Object.defineProperty(Chunk.prototype, "blocks", {
468468

469469
Object.defineProperty(Chunk.prototype, "entrypoints", {
470470
configurable: false,
471-
get: util.deprecate(function() {
472-
return this._entrypoints.getFromCache(getFrozenArray);
473-
}, "Chunk.entrypoints: The ChunkGroup could now be instanceof Entrypoint"),
474-
set: util.deprecate(function(value) {
475-
this.setEntrypoints(value);
476-
}, "Chunk.entrypoints: The ChunkGroup could now be instanceof Entrypoint")
471+
get() {
472+
throw new Error("Chunk.entrypoints: Use Chunks.groupsIterable and filter by instanceof Entrypoint instead");
473+
},
474+
set() {
475+
throw new Error("Chunk.entrypoints: Use Chunks.addGroup instead");
476+
}
477477
});
478478

479479
module.exports = Chunk;

lib/ChunkGroup.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ const sortById = (a, b) => {
1717
return 0;
1818
};
1919

20+
const sortOrigin = (a, b) => {
21+
const aIdent = a.module ? a.module.identifier() : "";
22+
const bIdent = b.module ? b.module.identifier() : "";
23+
if(aIdent < bIdent) return -1;
24+
if(aIdent > bIdent) return 1;
25+
return compareLocations(a.loc, b.loc);
26+
};
27+
2028
class ChunkGroup {
2129
constructor(name) {
2230
this.groupDebugId = debugId++;
@@ -78,14 +86,14 @@ class ChunkGroup {
7886
if(oldIdx < 0) return false;
7987
const newIdx = this.chunks.indexOf(newChunk);
8088
if(newIdx < 0) {
81-
this.chunks.splice(oldIdx, 1, newChunk);
89+
this.chunks[oldIdx] = newChunk;
8290
return true;
8391
}
8492
if(newIdx < oldIdx) {
8593
this.chunks.splice(oldIdx, 1);
8694
return true;
8795
} else {
88-
this.chunks.splice(oldIdx, 1, newChunk);
96+
this.chunks[oldIdx] = newChunk;
8997
this.chunks.splice(newIdx, 1);
9098
return true;
9199
}
@@ -105,7 +113,10 @@ class ChunkGroup {
105113
}
106114

107115
hasEntryModule() {
108-
return this.chunks.some(c => c.hasEntryModule());
116+
for(const chunk of this.chunks)
117+
if(chunk.hasEntryModule())
118+
return true;
119+
return false;
109120
}
110121

111122
addChild(chunk) {
@@ -277,13 +288,7 @@ class ChunkGroup {
277288
}
278289

279290
sortItems() {
280-
this.origins.sort((a, b) => {
281-
const aIdent = a.module ? a.module.identifier() : "";
282-
const bIdent = b.module ? b.module.identifier() : "";
283-
if(aIdent < bIdent) return -1;
284-
if(aIdent > bIdent) return 1;
285-
return compareLocations(a.loc, b.loc);
286-
});
291+
this.origins.sort(sortOrigin);
287292
this.origins.forEach(origin => {
288293
if(origin.reasons)
289294
origin.reasons.sort();

lib/WebpackOptionsDefaulter.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,7 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
173173
this.set("optimization.splitChunks.name", true);
174174
this.set("optimization.splitChunks.cacheGroups", {
175175
"vendors": {
176-
test: /[\\/]node_modules[\\/]/,
177-
minChunks: 1,
178-
chunks: "async"
176+
test: /[\\/]node_modules[\\/]/
179177
}
180178
});
181179
this.set("optimization.noEmitOnErrors", "make", options => isProductionLikeMode(options));

lib/util/createHash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BulkUpdateDecorator {
4040

4141
class DebugHash {
4242
constructor() {
43-
this.string = Buffer.alloc(0);
43+
this.string = "";
4444
}
4545

4646
update(data, inputEncoding) {

test/statsCases/split-chunks/a.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import "./d";
2+
import "./e";
3+
import "x";
4+
import "y";
5+
export default "a";
6+
import(/* webpackChunkName: "async-g" */ "./g");

test/statsCases/split-chunks/b.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./d";
2+
import "./f";
3+
import "x";
4+
import "y";
5+
export default "b";

test/statsCases/split-chunks/c.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import "./d";
2+
import "./f";
3+
import "x";
4+
import "z";
5+
export default "c";

test/statsCases/split-chunks/d.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "d";

test/statsCases/split-chunks/e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default "e";
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
Child default:
2+
Entrypoint main = default/main.js
3+
Entrypoint a = default/a.js
4+
Entrypoint b = default/b.js
5+
Entrypoint c = default/c.js
6+
chunk {0} default/async-b~async-c~async-g.js (async-b~async-c~async-g) 20 bytes <{1}> <{2}> <{3}> <{5}> <{10}> <{9}> ={4}= ={1}= ={8}= ={3}= ={7}= ={2}= ={6}= [rendered] split chunk (name: async-b~async-c~async-g)
7+
> ./g [] 6:0-47
8+
> ./g [] 6:0-47
9+
> ./c [8] ./index.js 3:0-47
10+
> ./b [8] ./index.js 2:0-47
11+
[2] ./f.js 20 bytes {0} {11} {12} [built]
12+
chunk {1} default/vendors~async-a~async-b~async-c.js (vendors~async-a~async-b~async-c) 20 bytes <{9}> ={0}= ={8}= ={3}= ={7}= ={2}= ={6}= ={5}= >{0}< >{4}< [rendered] split chunk (cache group: vendors) (name: vendors~async-a~async-b~async-c)
13+
> ./c [8] ./index.js 3:0-47
14+
> ./b [8] ./index.js 2:0-47
15+
> ./a [8] ./index.js 1:0-47
16+
[1] ./node_modules/x.js 20 bytes {1} {3} {10} {11} {12} [built]
17+
chunk {2} default/async-a~async-b.js (async-a~async-b) 20 bytes <{9}> ={0}= ={1}= ={6}= ={3}= ={5}= >{0}< >{4}< [rendered] split chunk (cache group: vendors) (name: vendors~async-a~async-b)
18+
> ./b [8] ./index.js 2:0-47
19+
> ./a [8] ./index.js 1:0-47
20+
[3] ./node_modules/y.js 20 bytes {2} {10} {11} [built]
21+
chunk {3} default/async-a~async-b~async-c.js (async-a~async-b~async-c) 40 bytes <{9}> ={0}= ={1}= ={8}= ={7}= ={2}= ={5}= >{0}< >{4}< [rendered] split chunk (name: async-a~async-b~async-c)
22+
> ./c [8] ./index.js 3:0-47
23+
> ./a [8] ./index.js 1:0-47
24+
[0] ./d.js 20 bytes {3} {6} {10} {11} {12} [built]
25+
[1] ./node_modules/x.js 20 bytes {1} {3} {10} {11} {12} [built]
26+
chunk {4} default/async-g.js (async-g) 34 bytes <{1}> <{2}> <{3}> <{5}> <{10}> ={0}= [rendered]
27+
> ./g [] 6:0-47
28+
> ./g [] 6:0-47
29+
[9] ./g.js 34 bytes {4} [built]
30+
chunk {5} default/async-a.js (async-a) 156 bytes <{9}> ={1}= ={2}= ={3}= >{0}< >{4}< [rendered]
31+
> ./a [8] ./index.js 1:0-47
32+
[7] ./a.js + 1 modules 156 bytes {5} {10} [built]
33+
| ./a.js 121 bytes [built]
34+
| ./e.js 20 bytes [built]
35+
chunk {6} default/async-b.js (async-b) 92 bytes <{9}> ={0}= ={1}= ={2}= [rendered]
36+
> ./b [8] ./index.js 2:0-47
37+
[0] ./d.js 20 bytes {3} {6} {10} {11} {12} [built]
38+
[5] ./b.js 72 bytes {6} {11} [built]
39+
chunk {7} default/async-c.js (async-c) 72 bytes <{9}> ={0}= ={1}= ={8}= ={3}= [rendered]
40+
> ./c [8] ./index.js 3:0-47
41+
[6] ./c.js 72 bytes {7} {12} [built]
42+
chunk {8} default/vendors~async-c.js (vendors~async-c) 20 bytes <{9}> ={0}= ={1}= ={3}= ={7}= [rendered] split chunk (cache group: vendors) (name: vendors~async-c)
43+
> ./c [8] ./index.js 3:0-47
44+
[4] ./node_modules/z.js 20 bytes {8} {12} [built]
45+
chunk {9} default/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{6}< >{8}< >{3}< >{7}< >{5}< [entry] [rendered]
46+
> ./ main
47+
[8] ./index.js 147 bytes {9} [built]
48+
chunk {10} default/a.js (a) 216 bytes >{0}< >{4}< [entry] [rendered]
49+
> ./a a
50+
[0] ./d.js 20 bytes {3} {6} {10} {11} {12} [built]
51+
[1] ./node_modules/x.js 20 bytes {1} {3} {10} {11} {12} [built]
52+
[3] ./node_modules/y.js 20 bytes {2} {10} {11} [built]
53+
[7] ./a.js + 1 modules 156 bytes {5} {10} [built]
54+
| ./a.js 121 bytes [built]
55+
| ./e.js 20 bytes [built]
56+
chunk {11} default/b.js (b) 152 bytes [entry] [rendered]
57+
> ./b b
58+
[0] ./d.js 20 bytes {3} {6} {10} {11} {12} [built]
59+
[1] ./node_modules/x.js 20 bytes {1} {3} {10} {11} {12} [built]
60+
[2] ./f.js 20 bytes {0} {11} {12} [built]
61+
[3] ./node_modules/y.js 20 bytes {2} {10} {11} [built]
62+
[5] ./b.js 72 bytes {6} {11} [built]
63+
chunk {12} default/c.js (c) 152 bytes [entry] [rendered]
64+
> ./c c
65+
[0] ./d.js 20 bytes {3} {6} {10} {11} {12} [built]
66+
[1] ./node_modules/x.js 20 bytes {1} {3} {10} {11} {12} [built]
67+
[2] ./f.js 20 bytes {0} {11} {12} [built]
68+
[4] ./node_modules/z.js 20 bytes {8} {12} [built]
69+
[6] ./c.js 72 bytes {7} {12} [built]
70+
Child all-chunks:
71+
Entrypoint main = default/main.js
72+
Entrypoint a = default/vendors~a~async-a~async-b~async-c~b~c.js default/vendors~a~async-a~async-b~b.js default/a.js
73+
Entrypoint b = default/async-b~async-c~async-g~b~c.js default/vendors~a~async-a~async-b~async-c~b~c.js default/b.js
74+
Entrypoint c = default/async-b~async-c~async-g~b~c.js default/vendors~a~async-a~async-b~async-c~b~c.js default/c.js
75+
chunk {0} default/async-b~async-c~async-g~b~c.js (async-b~async-c~async-g~b~c) 20 bytes <{1}> <{2}> <{11}> <{3}> <{4}> <{6}> <{10}> ={1}= ={13}= ={12}= ={5}= ={9}= ={4}= ={8}= ={2}= ={3}= ={7}= [initial] [rendered] split chunk (name: async-b~async-c~async-g~b~c)
76+
> ./c c
77+
> ./b b
78+
> ./g [] 6:0-47
79+
> ./g [] 6:0-47
80+
> ./c [8] ./index.js 3:0-47
81+
> ./b [8] ./index.js 2:0-47
82+
[3] ./f.js 20 bytes {0} [built]
83+
chunk {1} default/vendors~a~async-a~async-b~async-c~b~c.js (vendors~a~async-a~async-b~async-c~b~c) 20 bytes <{10}> ={0}= ={13}= ={12}= ={2}= ={11}= ={9}= ={4}= ={8}= ={3}= ={7}= ={6}= >{0}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~async-c~b~c)
84+
> ./c c
85+
> ./b b
86+
> ./a a
87+
> ./c [8] ./index.js 3:0-47
88+
> ./b [8] ./index.js 2:0-47
89+
> ./a [8] ./index.js 1:0-47
90+
[1] ./node_modules/x.js 20 bytes {1} {4} [built]
91+
chunk {2} default/vendors~a~async-a~async-b~b.js (vendors~a~async-a~async-b~b) 20 bytes <{10}> ={1}= ={11}= ={0}= ={3}= ={7}= ={4}= ={6}= >{0}< >{5}< [initial] [rendered] split chunk (cache group: vendors) (name: vendors~a~async-a~async-b~b)
92+
> ./a a
93+
> ./b [8] ./index.js 2:0-47
94+
> ./a [8] ./index.js 1:0-47
95+
[2] ./node_modules/y.js 20 bytes {2} {3} {12} [built]
96+
chunk {3} default/a~async-a~async-b~b.js (a~async-a~async-b~b) 20 bytes <{10}> ={0}= ={1}= ={2}= ={7}= ={4}= ={6}= >{0}< >{5}< [rendered] split chunk (name: a~async-a~async-b~b)
97+
> ./b [8] ./index.js 2:0-47
98+
> ./a [8] ./index.js 1:0-47
99+
[2] ./node_modules/y.js 20 bytes {2} {3} {12} [built]
100+
chunk {4} default/a~async-a~async-b~async-c~b~c.js (a~async-a~async-b~async-c~b~c) 40 bytes <{10}> ={0}= ={1}= ={9}= ={8}= ={2}= ={3}= ={6}= >{0}< >{5}< [rendered] split chunk (name: a~async-a~async-b~async-c~b~c)
101+
> ./c [8] ./index.js 3:0-47
102+
> ./a [8] ./index.js 1:0-47
103+
[0] ./d.js 20 bytes {4} {7} {11} {12} {13} [built]
104+
[1] ./node_modules/x.js 20 bytes {1} {4} [built]
105+
chunk {5} default/async-g.js (async-g) 34 bytes <{1}> <{2}> <{11}> <{3}> <{4}> <{6}> ={0}= [rendered]
106+
> ./g [] 6:0-47
107+
> ./g [] 6:0-47
108+
[9] ./g.js 34 bytes {5} [built]
109+
chunk {6} default/async-a.js (async-a) 156 bytes <{10}> ={1}= ={2}= ={3}= ={4}= >{0}< >{5}< [rendered]
110+
> ./a [8] ./index.js 1:0-47
111+
[7] ./a.js + 1 modules 156 bytes {6} {11} [built]
112+
| ./a.js 121 bytes [built]
113+
| ./e.js 20 bytes [built]
114+
chunk {7} default/async-b.js (async-b) 92 bytes <{10}> ={0}= ={1}= ={2}= ={3}= [rendered]
115+
> ./b [8] ./index.js 2:0-47
116+
[0] ./d.js 20 bytes {4} {7} {11} {12} {13} [built]
117+
[5] ./b.js 72 bytes {7} {12} [built]
118+
chunk {8} default/async-c.js (async-c) 72 bytes <{10}> ={0}= ={1}= ={9}= ={4}= [rendered]
119+
> ./c [8] ./index.js 3:0-47
120+
[6] ./c.js 72 bytes {8} {13} [built]
121+
chunk {9} default/vendors~async-c~c.js (vendors~async-c~c) 20 bytes <{10}> ={0}= ={1}= ={4}= ={8}= [rendered] split chunk (cache group: vendors) (name: vendors~async-c~c)
122+
> ./c [8] ./index.js 3:0-47
123+
[4] ./node_modules/z.js 20 bytes {9} {13} [built]
124+
chunk {10} default/main.js (main) 147 bytes >{0}< >{1}< >{2}< >{3}< >{7}< >{9}< >{4}< >{8}< >{6}< [entry] [rendered]
125+
> ./ main
126+
[8] ./index.js 147 bytes {10} [built]
127+
chunk {11} default/a.js (a) 176 bytes ={1}= ={2}= >{0}< >{5}< [entry] [rendered]
128+
> ./a a
129+
[0] ./d.js 20 bytes {4} {7} {11} {12} {13} [built]
130+
[7] ./a.js + 1 modules 156 bytes {6} {11} [built]
131+
| ./a.js 121 bytes [built]
132+
| ./e.js 20 bytes [built]
133+
chunk {12} default/b.js (b) 112 bytes ={0}= ={1}= [entry] [rendered]
134+
> ./b b
135+
[0] ./d.js 20 bytes {4} {7} {11} {12} {13} [built]
136+
[2] ./node_modules/y.js 20 bytes {2} {3} {12} [built]
137+
[5] ./b.js 72 bytes {7} {12} [built]
138+
chunk {13} default/c.js (c) 112 bytes ={0}= ={1}= [entry] [rendered]
139+
> ./c c
140+
[0] ./d.js 20 bytes {4} {7} {11} {12} {13} [built]
141+
[4] ./node_modules/z.js 20 bytes {9} {13} [built]
142+
[6] ./c.js 72 bytes {8} {13} [built]

0 commit comments

Comments
 (0)