Skip to content

Commit 56170c3

Browse files
authored
Merge pull request webpack#7093 from slavab89/add-assets-by-chunk-groups
Add assets by chunk groups to stats JSON
2 parents e5ee3be + da6c807 commit 56170c3

File tree

12 files changed

+173
-17
lines changed

12 files changed

+173
-17
lines changed

lib/Stats.js

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ class Stats {
135135
const showBuiltAt = optionOrLocalFallback(options.builtAt, true);
136136
const showAssets = optionOrLocalFallback(options.assets, true);
137137
const showEntrypoints = optionOrLocalFallback(options.entrypoints, true);
138+
const showChunkGroups = optionOrLocalFallback(
139+
options.chunkGroups,
140+
!forToString
141+
);
138142
const showChunks = optionOrLocalFallback(options.chunks, !forToString);
139143
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
140144
const showChunkOrigins = optionOrLocalFallback(
@@ -396,15 +400,15 @@ class Stats {
396400
obj.assets.sort(sortByField(sortAssets));
397401
}
398402

399-
if (showEntrypoints) {
400-
obj.entrypoints = {};
401-
for (const keyValuePair of compilation.entrypoints) {
403+
const fnChunkGroup = groupMap => {
404+
const obj = {};
405+
for (const keyValuePair of groupMap) {
402406
const name = keyValuePair[0];
403-
const ep = keyValuePair[1];
404-
const children = ep.getChildrenByOrders();
405-
obj.entrypoints[name] = {
406-
chunks: ep.chunks.map(c => c.id),
407-
assets: ep.chunks.reduce(
407+
const cg = keyValuePair[1];
408+
const children = cg.getChildrenByOrders();
409+
obj[name] = {
410+
chunks: cg.chunks.map(c => c.id),
411+
assets: cg.chunks.reduce(
408412
(array, c) => array.concat(c.files || []),
409413
[]
410414
),
@@ -436,9 +440,19 @@ class Stats {
436440
}, Object.create(null))
437441
};
438442
if (showPerformance) {
439-
obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
443+
obj[name].isOverSizeLimit = cg.isOverSizeLimit;
440444
}
441445
}
446+
447+
return obj;
448+
};
449+
450+
if (showEntrypoints) {
451+
obj.entrypoints = fnChunkGroup(compilation.entrypoints);
452+
}
453+
454+
if (showChunkGroups) {
455+
obj.namedChunkGroups = fnChunkGroup(compilation.namedChunkGroups);
442456
}
443457

444458
const fnModule = module => {
@@ -866,22 +880,23 @@ class Stats {
866880
colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
867881
newline();
868882
}
869-
if (obj.entrypoints) {
870-
for (const name of Object.keys(obj.entrypoints)) {
871-
const ep = obj.entrypoints[name];
872-
colors.normal("Entrypoint ");
883+
884+
const processChunkGroups = (namedGroups, prefix) => {
885+
for (const name of Object.keys(namedGroups)) {
886+
const cg = namedGroups[name];
887+
colors.normal(`${prefix} `);
873888
colors.bold(name);
874-
if (ep.isOverSizeLimit) {
889+
if (cg.isOverSizeLimit) {
875890
colors.normal(" ");
876891
colors.yellow("[big]");
877892
}
878893
colors.normal(" =");
879-
for (const asset of ep.assets) {
894+
for (const asset of cg.assets) {
880895
colors.normal(" ");
881896
colors.green(asset);
882897
}
883-
for (const name of Object.keys(ep.childAssets)) {
884-
const assets = ep.childAssets[name];
898+
for (const name of Object.keys(cg.childAssets)) {
899+
const assets = cg.childAssets[name];
885900
if (assets && assets.length > 0) {
886901
colors.normal(" ");
887902
colors.magenta(`(${name}:`);
@@ -894,7 +909,25 @@ class Stats {
894909
}
895910
newline();
896911
}
912+
};
913+
914+
if (obj.entrypoints) {
915+
processChunkGroups(obj.entrypoints, "Entrypoint");
897916
}
917+
918+
if (obj.namedChunkGroups) {
919+
let outputChunkGroups = obj.namedChunkGroups;
920+
if (obj.entrypoints) {
921+
outputChunkGroups = Object.keys(outputChunkGroups)
922+
.filter(name => !obj.entrypoints[name])
923+
.reduce((result, name) => {
924+
result[name] = obj.namedChunkGroups[name];
925+
return result;
926+
}, {});
927+
}
928+
processChunkGroups(outputChunkGroups, "Chunk Group");
929+
}
930+
898931
const modulesByIdentifier = {};
899932
if (obj.modules) {
900933
for (const module of obj.modules) {
@@ -1260,6 +1293,7 @@ class Stats {
12601293
case "verbose":
12611294
return {
12621295
entrypoints: true,
1296+
chunkGroups: true,
12631297
modules: false,
12641298
chunks: true,
12651299
chunkModules: true,
@@ -1278,6 +1312,7 @@ class Stats {
12781312
case "detailed":
12791313
return {
12801314
entrypoints: true,
1315+
chunkGroups: true,
12811316
chunks: true,
12821317
chunkModules: false,
12831318
chunkOrigins: true,

schemas/WebpackOptions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,6 +1853,10 @@
18531853
"type": "boolean",
18541854
"description": "Display the entry points with the corresponding bundles"
18551855
},
1856+
"chunkGroups": {
1857+
"type": "boolean",
1858+
"description": "Display all chunk groups with the corresponding bundles"
1859+
},
18561860
"errorDetails": {
18571861
"type": "boolean",
18581862
"description": "add details to errors (like resolving log)"

test/Stats.unittest.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ describe(
116116
warnings: [],
117117
assets: [],
118118
entrypoints: new Map(),
119+
namedChunkGroups: new Map(),
119120
chunks: [],
120121
modules: [],
121122
children: [],
@@ -142,6 +143,7 @@ describe(
142143
assets: [],
143144
entrypoints: new Map(),
144145
chunks: [],
146+
namedChunkGroups: new Map(),
145147
modules: [],
146148
children: [],
147149
hash: "1234",
@@ -162,6 +164,7 @@ describe(
162164
children: [],
163165
chunks: [],
164166
entrypoints: {},
167+
namedChunkGroups: {},
165168
filteredAssets: 0,
166169
filteredModules: 0,
167170
errors: [],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./shared";
2+
3+
export default "a";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./shared";
2+
3+
export default "b";
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import "x";
2+
import "y";
3+
4+
export default "c";
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Child
2+
Chunk Group main = main.js
3+
Chunk Group async-a = async-a~async-b.js async-a.js
4+
Chunk Group async-b = async-a~async-b.js async-b.js
5+
Chunk Group async-c = vendors.js async-c.js
6+
chunk {0} async-a~async-b.js (async-a~async-b) 133 bytes <{5}> ={1}= ={2}= [rendered] split chunk (cache group: default) (name: async-a~async-b)
7+
> ./a [6] ./index.js 1:0-47
8+
> ./b [6] ./index.js 2:0-47
9+
[0] ./shared.js 133 bytes {0} [built]
10+
chunk {1} async-a.js (async-a) 40 bytes <{5}> ={0}= [rendered]
11+
> ./a [6] ./index.js 1:0-47
12+
[3] ./a.js 40 bytes {1} [built]
13+
chunk {2} async-b.js (async-b) 40 bytes <{5}> ={0}= [rendered]
14+
> ./b [6] ./index.js 2:0-47
15+
[4] ./b.js 40 bytes {2} [built]
16+
chunk {3} async-c.js (async-c) 45 bytes <{5}> ={4}= [rendered]
17+
> ./c [6] ./index.js 3:0-47
18+
[5] ./c.js 45 bytes {3} [built]
19+
chunk {4} vendors.js (vendors) 40 bytes <{5}> ={3}= [rendered] split chunk (cache group: vendors) (name: vendors)
20+
> ./c [6] ./index.js 3:0-47
21+
[1] ./node_modules/x.js 20 bytes {4} [built]
22+
[2] ./node_modules/y.js 20 bytes {4} [built]
23+
chunk {5} main.js (main) 146 bytes >{0}< >{1}< >{2}< >{3}< >{4}< [entry] [rendered]
24+
> ./ main
25+
[6] ./index.js 146 bytes {5} [built]
26+
Child
27+
Entrypoint main = main.js
28+
Chunk Group async-a = async-a~async-b.js async-a.js
29+
Chunk Group async-b = async-a~async-b.js async-b.js
30+
Chunk Group async-c = vendors.js async-c.js
31+
chunk {0} async-a~async-b.js (async-a~async-b) 133 bytes <{5}> ={1}= ={2}= [rendered] split chunk (cache group: default) (name: async-a~async-b)
32+
> ./a [6] ./index.js 1:0-47
33+
> ./b [6] ./index.js 2:0-47
34+
[0] ./shared.js 133 bytes {0} [built]
35+
chunk {1} async-a.js (async-a) 40 bytes <{5}> ={0}= [rendered]
36+
> ./a [6] ./index.js 1:0-47
37+
[3] ./a.js 40 bytes {1} [built]
38+
chunk {2} async-b.js (async-b) 40 bytes <{5}> ={0}= [rendered]
39+
> ./b [6] ./index.js 2:0-47
40+
[4] ./b.js 40 bytes {2} [built]
41+
chunk {3} async-c.js (async-c) 45 bytes <{5}> ={4}= [rendered]
42+
> ./c [6] ./index.js 3:0-47
43+
[5] ./c.js 45 bytes {3} [built]
44+
chunk {4} vendors.js (vendors) 40 bytes <{5}> ={3}= [rendered] split chunk (cache group: vendors) (name: vendors)
45+
> ./c [6] ./index.js 3:0-47
46+
[1] ./node_modules/x.js 20 bytes {4} [built]
47+
[2] ./node_modules/y.js 20 bytes {4} [built]
48+
chunk {5} main.js (main) 146 bytes >{0}< >{1}< >{2}< >{3}< >{4}< [entry] [rendered]
49+
> ./ main
50+
[6] ./index.js 146 bytes {5} [built]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import(/* webpackChunkName: "async-a" */ "./a");
2+
import(/* webpackChunkName: "async-b" */ "./b");
3+
import(/* webpackChunkName: "async-c" */ "./c");

test/statsCases/named-chunk-groups/node_modules/x.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/statsCases/named-chunk-groups/node_modules/y.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)