Skip to content

Commit 5e18c1c

Browse files
committed
WIP7
1 parent 995ceab commit 5e18c1c

File tree

20 files changed

+286
-157
lines changed

20 files changed

+286
-157
lines changed

lib/ChunkGroup.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ class ChunkGroup {
220220
}
221221

222222
addOrigin(module, loc, request) {
223-
if(!module) throw new Error("No origin module");
224223
this.origins.push({
225224
module,
226225
loc,
@@ -279,8 +278,8 @@ class ChunkGroup {
279278

280279
sortItems() {
281280
this.origins.sort((a, b) => {
282-
const aIdent = a.module.identifier();
283-
const bIdent = b.module.identifier();
281+
const aIdent = a.module ? a.module.identifier() : "";
282+
const bIdent = b.module ? b.module.identifier() : "";
284283
if(aIdent < bIdent) return -1;
285284
if(aIdent > bIdent) return 1;
286285
return compareLocations(a.loc, b.loc);

lib/Compilation.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,7 @@ class Compilation extends Tapable {
650650
addEntry(context, entry, name, callback) {
651651
const slot = {
652652
name: name,
653+
request: entry.request,
653654
module: null
654655
};
655656
this._preparedEntrypoints.push(slot);
@@ -753,6 +754,7 @@ class Compilation extends Tapable {
753754
const name = preparedEntrypoint.name;
754755
const chunk = this.addChunk(name);
755756
const entrypoint = new Entrypoint(name);
757+
entrypoint.addOrigin(null, name, preparedEntrypoint.request);
756758
this.namedChunkGroups.set(name, entrypoint);
757759
this.entrypoints.set(name, entrypoint);
758760
this.chunkGroups.push(entrypoint);
@@ -1063,6 +1065,7 @@ class Compilation extends Tapable {
10631065
// Start with the provided modules/chunks
10641066
const queue = inputChunkGroups.map(chunkGroup => ({
10651067
block: chunkGroup.chunks[0].entryModule,
1068+
module: chunkGroup.chunks[0].entryModule,
10661069
chunk: chunkGroup.chunks[0],
10671070
chunkGroup
10681071
}));

lib/Stats.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,9 @@ class Stats {
940940
colors.bold(module.name);
941941
colors.normal(" ");
942942
}
943-
if(origin.loc) {
944-
colors.normal(origin.loc);
945-
}
943+
}
944+
if(origin.loc) {
945+
colors.normal(origin.loc);
946946
}
947947
newline();
948948
});

lib/optimize/AggressiveSplittingPlugin.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ class AggressiveSplittingPlugin {
8888
if(splitData.id !== null && splitData.id !== undefined) {
8989
newChunk.id = splitData.id;
9090
}
91-
newChunk.origins = chunk.origins.map(copyWithReason);
92-
chunk.origins = chunk.origins.map(copyWithReason);
9391
return true;
9492
} else { // chunk is identical to the split
9593
if(j < savedSplits.length)
@@ -141,8 +139,6 @@ class AggressiveSplittingPlugin {
141139
if(newChunk.getNumberOfModules() > 0) {
142140
chunk.split(newChunk);
143141
chunk.name = null;
144-
newChunk.origins = chunk.origins.map(copyWithReason);
145-
chunk.origins = chunk.origins.map(copyWithReason);
146142
compilation._aggressiveSplittingSplits = (compilation._aggressiveSplittingSplits || []).concat({
147143
modules: newChunk.mapModules(m => identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache))
148144
});

lib/web/JsonpMainTemplatePlugin.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,16 @@ class JsonpMainTemplatePlugin {
162162
});
163163
mainTemplate.hooks.bootstrap.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
164164
if(needChunkLoadingCode(chunk)) {
165+
const withDefer = needEntryDeferringCode(chunk);
165166
return Template.asString([
166167
source,
167168
"",
168169
"// install a JSONP callback for chunk loading",
169170
"function webpackJsonpCallback(data) {",
170171
Template.indent([
171-
"var chunkIds = data[0], moreModules = data[1], executeModules = data[2];",
172+
"var chunkIds = data[0];",
173+
"var moreModules = data[1]",
174+
withDefer ? "var executeModules = data[2];" : "",
172175
"// add \"moreModules\" to the modules object,",
173176
"// then flag all \"chunkIds\" as loaded and fire callback",
174177
"var moduleId, chunkId, i = 0, resolves = [];",
@@ -192,7 +195,7 @@ class JsonpMainTemplatePlugin {
192195
"while(resolves.length) {",
193196
Template.indent("resolves.shift()();"),
194197
"}",
195-
needEntryDeferringCode(chunk) ? Template.asString([
198+
withDefer ? Template.asString([
196199
"",
197200
"// add entry modules from loaded chunk to deferred list",
198201
"deferredModules.push.apply(deferredModules, executeModules || []);",
@@ -202,7 +205,7 @@ class JsonpMainTemplatePlugin {
202205
]) : ""
203206
]),
204207
"};",
205-
needEntryDeferringCode(chunk) ? Template.asString([
208+
withDefer ? Template.asString([
206209
"function checkDeferredModules() {",
207210
Template.indent([
208211
"var result;",

test/statsCases/async-commons-chunk-all-selected/a.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/statsCases/async-commons-chunk-all-selected/b.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/statsCases/async-commons-chunk-all-selected/c.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/statsCases/async-commons-chunk-all-selected/expected.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.

test/statsCases/async-commons-chunk-all-selected/index.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/statsCases/async-commons-chunk-all-selected/webpack.config.js

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
Child async-only:
2+
Entrypoint main = async-only/main.js
3+
Entrypoint a = async-only/a.js
4+
Entrypoint b = async-only/b.js
5+
Entrypoint c = async-only/c.js
6+
chunk {0} async-only/0.js 40 bytes <{7}> ={1}= ={6}= ={2}= ={5}= ={4}= >{1}< >{3}< [rendered] commons chunk
7+
> ./c [7] ./index.js 3:0-13
8+
> ./b [7] ./index.js 2:0-13
9+
> ./a [7] ./index.js 1:0-13
10+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
11+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
12+
chunk {1} async-only/1.js 20 bytes <{0}> <{2}> <{4}> <{8}> <{7}> ={3}= ={0}= ={6}= ={2}= ={5}= [rendered] commons chunk
13+
> ./g [] 6:0-13
14+
> ./g [] 6:0-13
15+
> ./c [7] ./index.js 3:0-13
16+
> ./b [7] ./index.js 2:0-13
17+
[2] ./f.js 20 bytes {1} {9} {10} [built]
18+
chunk {2} async-only/2.js 20 bytes <{7}> ={0}= ={1}= ={5}= ={4}= >{1}< >{3}< [rendered] commons chunk
19+
> ./b [7] ./index.js 2:0-13
20+
> ./a [7] ./index.js 1:0-13
21+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
22+
chunk {3} async-only/3.js 34 bytes <{0}> <{2}> <{4}> <{8}> ={1}= [rendered]
23+
> ./g [] 6:0-13
24+
> ./g [] 6:0-13
25+
[8] ./g.js 34 bytes {3} [built]
26+
chunk {4} async-only/4.js 122 bytes <{7}> ={0}= ={2}= >{1}< >{3}< [rendered]
27+
> ./a [7] ./index.js 1:0-13
28+
[5] ./a.js + 1 modules 122 bytes {4} {8} [built]
29+
| ./a.js 87 bytes [built]
30+
| ./e.js 20 bytes [built]
31+
chunk {5} async-only/5.js 72 bytes <{7}> ={0}= ={2}= ={1}= [rendered]
32+
> ./b [7] ./index.js 2:0-13
33+
[4] ./b.js 72 bytes {5} {9} [built]
34+
chunk {6} async-only/6.js 107 bytes <{7}> ={0}= ={1}= [rendered]
35+
> ./c [7] ./index.js 3:0-13
36+
[6] ./c.js + 1 modules 107 bytes {6} {10} [built]
37+
| ./c.js 72 bytes [built]
38+
| ./node_modules/z.js 20 bytes [built]
39+
chunk {7} async-only/main.js (main) 45 bytes >{0}< >{1}< >{6}< >{2}< >{5}< >{4}< [entry] [rendered]
40+
> ./ main
41+
[7] ./index.js 45 bytes {7} [built]
42+
chunk {8} async-only/a.js (a) 182 bytes >{1}< >{3}< [entry] [rendered]
43+
> ./a a
44+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
45+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
46+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
47+
[5] ./a.js + 1 modules 122 bytes {4} {8} [built]
48+
| ./a.js 87 bytes [built]
49+
| ./e.js 20 bytes [built]
50+
chunk {9} async-only/b.js (b) 152 bytes [entry] [rendered]
51+
> ./b b
52+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
53+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
54+
[2] ./f.js 20 bytes {1} {9} {10} [built]
55+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
56+
[4] ./b.js 72 bytes {5} {9} [built]
57+
chunk {10} async-only/c.js (c) 167 bytes [entry] [rendered]
58+
> ./c c
59+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
60+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
61+
[2] ./f.js 20 bytes {1} {9} {10} [built]
62+
[6] ./c.js + 1 modules 107 bytes {6} {10} [built]
63+
| ./c.js 72 bytes [built]
64+
| ./node_modules/z.js 20 bytes [built]
65+
Child vendors1:
66+
Entrypoint main = vendors1/main.js
67+
Entrypoint a = vendors1/vendors.js vendors1/10.js vendors1/a.js
68+
Entrypoint b = vendors1/vendors.js vendors1/9.js vendors1/10.js vendors1/b.js
69+
Entrypoint c = vendors1/vendors.js vendors1/9.js vendors1/10.js vendors1/c.js
70+
chunk {0} vendors1/0.js 54 bytes <{1}> <{8}> <{10}> <{5}> [rendered]
71+
> ./g [] 6:0-13
72+
> ./g [] 6:0-13
73+
[2] ./f.js 20 bytes {0} {2} {3} {9} [built]
74+
[8] ./g.js 34 bytes {0} [built]
75+
chunk {1} vendors1/1.js 182 bytes <{4}> >{0}< [rendered]
76+
> ./a [7] ./index.js 1:0-13
77+
[0] ./d.js 20 bytes {1} {2} {3} {10} [built]
78+
[1] ./node_modules/x.js 20 bytes {1} {2} {3} {8} [built]
79+
[3] ./node_modules/y.js 20 bytes {1} {2} {8} [built]
80+
[5] ./a.js + 1 modules 122 bytes {1} {5} [built]
81+
| ./a.js 87 bytes [built]
82+
| ./e.js 20 bytes [built]
83+
chunk {2} vendors1/2.js 152 bytes <{4}> [rendered]
84+
> ./b [7] ./index.js 2:0-13
85+
[0] ./d.js 20 bytes {1} {2} {3} {10} [built]
86+
[1] ./node_modules/x.js 20 bytes {1} {2} {3} {8} [built]
87+
[2] ./f.js 20 bytes {0} {2} {3} {9} [built]
88+
[3] ./node_modules/y.js 20 bytes {1} {2} {8} [built]
89+
[4] ./b.js 72 bytes {2} {6} [built]
90+
chunk {3} vendors1/3.js 167 bytes <{4}> [rendered]
91+
> ./c [7] ./index.js 3:0-13
92+
[0] ./d.js 20 bytes {1} {2} {3} {10} [built]
93+
[1] ./node_modules/x.js 20 bytes {1} {2} {3} {8} [built]
94+
[2] ./f.js 20 bytes {0} {2} {3} {9} [built]
95+
[6] ./c.js + 1 modules 107 bytes {3} {7} [built]
96+
| ./c.js 72 bytes [built]
97+
| ./node_modules/z.js 20 bytes [built]
98+
chunk {4} vendors1/main.js (main) 45 bytes >{1}< >{2}< >{3}< [entry] [rendered]
99+
> ./ main
100+
[7] ./index.js 45 bytes {4} [built]
101+
chunk {5} vendors1/a.js (a) 122 bytes ={8}= ={10}= >{0}< [initial] [rendered]
102+
> ./a a
103+
[5] ./a.js + 1 modules 122 bytes {1} {5} [built]
104+
| ./a.js 87 bytes [built]
105+
| ./e.js 20 bytes [built]
106+
chunk {6} vendors1/b.js (b) 72 bytes ={8}= ={9}= ={10}= [initial] [rendered]
107+
> ./b b
108+
[4] ./b.js 72 bytes {2} {6} [built]
109+
chunk {7} vendors1/c.js (c) 107 bytes ={8}= ={9}= ={10}= [initial] [rendered]
110+
> ./c c
111+
[6] ./c.js + 1 modules 107 bytes {3} {7} [built]
112+
| ./c.js 72 bytes [built]
113+
| ./node_modules/z.js 20 bytes [built]
114+
chunk {8} vendors1/vendors.js (vendors) 40 bytes ={9}= ={10}= ={7}= ={6}= ={5}= >{0}< [entry] [rendered] commons chunk vendors
115+
> ./c c
116+
> ./b b
117+
> ./a a
118+
[1] ./node_modules/x.js 20 bytes {1} {2} {3} {8} [built]
119+
[3] ./node_modules/y.js 20 bytes {1} {2} {8} [built]
120+
chunk {9} vendors1/9.js 20 bytes ={8}= ={10}= ={7}= ={6}= [initial] [rendered] commons chunk
121+
> ./c c
122+
> ./b b
123+
[2] ./f.js 20 bytes {0} {2} {3} {9} [built]
124+
chunk {10} vendors1/10.js 20 bytes ={8}= ={9}= ={7}= ={6}= ={5}= >{0}< [initial] [rendered] commons chunk
125+
> ./c c
126+
> ./b b
127+
> ./a a
128+
[0] ./d.js 20 bytes {1} {2} {3} {10} [built]
129+
Child async-and-vendor:
130+
Entrypoint main = async-and-vendor/main.js
131+
Entrypoint a = async-and-vendor/a.js
132+
Entrypoint b = async-and-vendor/b.js
133+
Entrypoint c = async-and-vendor/c.js
134+
Entrypoint vendors = async-and-vendor/vendors.js
135+
chunk {0} async-and-vendor/0.js 40 bytes <{7}> ={1}= ={6}= ={2}= ={5}= ={4}= >{1}< >{3}< [rendered] commons chunk
136+
> ./c [7] ./index.js 3:0-13
137+
> ./b [7] ./index.js 2:0-13
138+
> ./a [7] ./index.js 1:0-13
139+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
140+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
141+
chunk {1} async-and-vendor/1.js 20 bytes <{0}> <{2}> <{4}> <{8}> <{7}> ={3}= ={0}= ={6}= ={2}= ={5}= [rendered] commons chunk
142+
> ./g [] 6:0-13
143+
> ./g [] 6:0-13
144+
> ./c [7] ./index.js 3:0-13
145+
> ./b [7] ./index.js 2:0-13
146+
[2] ./f.js 20 bytes {1} {9} {10} [built]
147+
chunk {2} async-and-vendor/2.js 20 bytes <{7}> ={0}= ={1}= ={5}= ={4}= >{1}< >{3}< [rendered] commons chunk
148+
> ./b [7] ./index.js 2:0-13
149+
> ./a [7] ./index.js 1:0-13
150+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
151+
chunk {3} async-and-vendor/3.js 34 bytes <{0}> <{2}> <{4}> <{8}> ={1}= [rendered]
152+
> ./g [] 6:0-13
153+
> ./g [] 6:0-13
154+
[9] ./g.js 34 bytes {3} [built]
155+
chunk {4} async-and-vendor/4.js 122 bytes <{7}> ={0}= ={2}= >{1}< >{3}< [rendered]
156+
> ./a [7] ./index.js 1:0-13
157+
[5] ./a.js + 1 modules 122 bytes {4} {8} [built]
158+
| ./a.js 87 bytes [built]
159+
| ./e.js 20 bytes [built]
160+
chunk {5} async-and-vendor/5.js 72 bytes <{7}> ={0}= ={2}= ={1}= [rendered]
161+
> ./b [7] ./index.js 2:0-13
162+
[4] ./b.js 72 bytes {5} {9} [built]
163+
chunk {6} async-and-vendor/6.js 107 bytes <{7}> ={0}= ={1}= [rendered]
164+
> ./c [7] ./index.js 3:0-13
165+
[6] ./c.js + 1 modules 107 bytes {6} {10} [built]
166+
| ./c.js 72 bytes [built]
167+
| ./node_modules/z.js 20 bytes [built]
168+
chunk {7} async-and-vendor/main.js (main) 45 bytes >{0}< >{1}< >{6}< >{2}< >{5}< >{4}< [entry] [rendered]
169+
> ./ main
170+
[7] ./index.js 45 bytes {7} [built]
171+
chunk {8} async-and-vendor/a.js (a) 182 bytes >{1}< >{3}< [entry] [rendered]
172+
> ./a a
173+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
174+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
175+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
176+
[5] ./a.js + 1 modules 122 bytes {4} {8} [built]
177+
| ./a.js 87 bytes [built]
178+
| ./e.js 20 bytes [built]
179+
chunk {9} async-and-vendor/b.js (b) 152 bytes [entry] [rendered]
180+
> ./b b
181+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
182+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
183+
[2] ./f.js 20 bytes {1} {9} {10} [built]
184+
[3] ./node_modules/y.js 20 bytes {2} {8} {9} [built]
185+
[4] ./b.js 72 bytes {5} {9} [built]
186+
chunk {10} async-and-vendor/c.js (c) 167 bytes [entry] [rendered]
187+
> ./c c
188+
[0] ./d.js 20 bytes {0} {8} {9} {10} [built]
189+
[1] ./node_modules/x.js 20 bytes {0} {8} {9} {10} [built]
190+
[2] ./f.js 20 bytes {1} {9} {10} [built]
191+
[6] ./c.js + 1 modules 107 bytes {6} {10} [built]
192+
| ./c.js 72 bytes [built]
193+
| ./node_modules/z.js 20 bytes [built]
194+
chunk {11} async-and-vendor/vendors.js (vendors) 21 bytes [entry] [rendered]
195+
> xy vendors
196+
[8] ./node_modules/xy.js 21 bytes {11} [built]

test/statsCases/async-commons-chunk/webpack.config.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
var webpack = require("../../../");
2-
31
module.exports = {
42
mode: "production",
53
entry: "./",
6-
plugins: [
7-
new webpack.optimize.CommonsChunkPlugin({
8-
name: "main",
9-
async: true
10-
})
11-
],
4+
optimization: {
5+
asyncCommonsChunks: {
6+
minSize: 1
7+
}
8+
},
129
stats: {
1310
hash: false,
1411
timings: false,

0 commit comments

Comments
 (0)