Skip to content

Commit 71a12c8

Browse files
committed
Add tests for namedChunkGroups
1 parent 9ea1999 commit 71a12c8

File tree

11 files changed

+112
-9
lines changed

11 files changed

+112
-9
lines changed

lib/Stats.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +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(options.chunkGroups, true);
138+
const showChunkGroups = optionOrLocalFallback(
139+
options.chunkGroups,
140+
!forToString
141+
);
139142
const showChunks = optionOrLocalFallback(options.chunks, !forToString);
140143
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
141144
const showChunkOrigins = optionOrLocalFallback(
@@ -877,22 +880,23 @@ class Stats {
877880
colors.normal(obj.filteredAssets !== 1 ? " assets" : " asset");
878881
newline();
879882
}
880-
if (obj.entrypoints) {
881-
for (const name of Object.keys(obj.entrypoints)) {
882-
const ep = obj.entrypoints[name];
883-
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} `);
884888
colors.bold(name);
885-
if (ep.isOverSizeLimit) {
889+
if (cg.isOverSizeLimit) {
886890
colors.normal(" ");
887891
colors.yellow("[big]");
888892
}
889893
colors.normal(" =");
890-
for (const asset of ep.assets) {
894+
for (const asset of cg.assets) {
891895
colors.normal(" ");
892896
colors.green(asset);
893897
}
894-
for (const name of Object.keys(ep.childAssets)) {
895-
const assets = ep.childAssets[name];
898+
for (const name of Object.keys(cg.childAssets)) {
899+
const assets = cg.childAssets[name];
896900
if (assets && assets.length > 0) {
897901
colors.normal(" ");
898902
colors.magenta(`(${name}:`);
@@ -905,7 +909,25 @@ class Stats {
905909
}
906910
newline();
907911
}
912+
};
913+
914+
if (obj.entrypoints) {
915+
processChunkGroups(obj.entrypoints, "Entrypoint");
908916
}
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+
909931
const modulesByIdentifier = {};
910932
if (obj.modules) {
911933
for (const module of obj.modules) {
@@ -1271,6 +1293,7 @@ class Stats {
12711293
case "verbose":
12721294
return {
12731295
entrypoints: true,
1296+
chunkGroups: true,
12741297
modules: false,
12751298
chunks: true,
12761299
chunkModules: true,
@@ -1289,6 +1312,7 @@ class Stats {
12891312
case "detailed":
12901313
return {
12911314
entrypoints: true,
1315+
chunkGroups: true,
12921316
chunks: true,
12931317
chunkModules: false,
12941318
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)"
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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Chunk Group main = main.js
2+
Chunk Group async-a = async-a~async-b.js async-a.js
3+
Chunk Group async-b = async-a~async-b.js async-b.js
4+
Chunk Group async-c = vendors.js async-c.js
5+
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)
6+
> ./a [6] ./index.js 1:0-47
7+
> ./b [6] ./index.js 2:0-47
8+
[0] ./shared.js 133 bytes {0} [built]
9+
chunk {1} async-a.js (async-a) 40 bytes <{5}> ={0}= [rendered]
10+
> ./a [6] ./index.js 1:0-47
11+
[3] ./a.js 40 bytes {1} [built]
12+
chunk {2} async-b.js (async-b) 40 bytes <{5}> ={0}= [rendered]
13+
> ./b [6] ./index.js 2:0-47
14+
[4] ./b.js 40 bytes {2} [built]
15+
chunk {3} async-c.js (async-c) 45 bytes <{5}> ={4}= [rendered]
16+
> ./c [6] ./index.js 3:0-47
17+
[5] ./c.js 45 bytes {3} [built]
18+
chunk {4} vendors.js (vendors) 40 bytes <{5}> ={3}= [rendered] split chunk (cache group: vendors) (name: vendors)
19+
> ./c [6] ./index.js 3:0-47
20+
[1] ./node_modules/x.js 20 bytes {4} [built]
21+
[2] ./node_modules/y.js 20 bytes {4} [built]
22+
chunk {5} main.js (main) 146 bytes >{0}< >{1}< >{2}< >{3}< >{4}< [entry] [rendered]
23+
> ./ main
24+
[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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// content content content content content content content content
2+
// content content content content content content content content

0 commit comments

Comments
 (0)