Skip to content

Commit a95f414

Browse files
committed
Add assets by chunk groups to stats JSON
1 parent e7c8fa4 commit a95f414

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/Stats.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ 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(options.chunkGroups, true);
138139
const showChunks = optionOrLocalFallback(options.chunks, !forToString);
139140
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
140141
const showChunkOrigins = optionOrLocalFallback(
@@ -396,15 +397,15 @@ class Stats {
396397
obj.assets.sort(sortByField(sortAssets));
397398
}
398399

399-
if (showEntrypoints) {
400-
obj.entrypoints = {};
401-
for (const keyValuePair of compilation.entrypoints) {
400+
const fnChunkGroup = groupMap => {
401+
const obj = {};
402+
for (const keyValuePair of groupMap) {
402403
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(
404+
const cg = keyValuePair[1];
405+
const children = cg.getChildrenByOrders();
406+
obj[name] = {
407+
chunks: cg.chunks.map(c => c.id),
408+
assets: cg.chunks.reduce(
408409
(array, c) => array.concat(c.files || []),
409410
[]
410411
),
@@ -436,9 +437,19 @@ class Stats {
436437
}, Object.create(null))
437438
};
438439
if (showPerformance) {
439-
obj.entrypoints[name].isOverSizeLimit = ep.isOverSizeLimit;
440+
obj[name].isOverSizeLimit = cg.isOverSizeLimit;
440441
}
441442
}
443+
444+
return obj;
445+
};
446+
447+
if (showEntrypoints) {
448+
obj.entrypoints = fnChunkGroup(compilation.entrypoints);
449+
}
450+
451+
if (showChunkGroups) {
452+
obj.chunkGroups = fnChunkGroup(compilation.namedChunkGroups);
442453
}
443454

444455
const fnModule = module => {

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+
chunkGroups: {},
165168
filteredAssets: 0,
166169
filteredModules: 0,
167170
errors: [],

0 commit comments

Comments
 (0)