Skip to content

Commit ba00d74

Browse files
committed
fix unnecessary module concatenation
allow to display nested modules in stats
1 parent 7b7b2cd commit ba00d74

File tree

18 files changed

+101
-12
lines changed

18 files changed

+101
-12
lines changed

lib/Stats.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Stats {
109109
const showChunkModules = optionOrLocalFallback(options.chunkModules, true);
110110
const showChunkOrigins = optionOrLocalFallback(options.chunkOrigins, !forToString);
111111
const showModules = optionOrLocalFallback(options.modules, true);
112+
const showNestedModules = optionOrLocalFallback(options.nestedModules, true);
112113
const showDepth = optionOrLocalFallback(options.depth, !forToString);
113114
const showCachedModules = optionOrLocalFallback(options.cached, true);
114115
const showCachedAssets = optionOrLocalFallback(options.cachedAssets, true);
@@ -385,6 +386,17 @@ class Stats {
385386
if(showDepth) {
386387
obj.depth = module.depth;
387388
}
389+
if(showNestedModules) {
390+
if(module.modules) {
391+
const modules = module.modules;
392+
obj.modules = modules
393+
.sort(sortByField("depth"))
394+
.filter(createModuleFilter())
395+
.map(fnModule);
396+
obj.filteredModules = modules.length - obj.modules.length;
397+
obj.modules.sort(sortByField(sortModules));
398+
}
399+
}
388400
if(showSource && module._source) {
389401
obj.source = module._source.source();
390402
}
@@ -792,26 +804,34 @@ class Stats {
792804
coloredTime(sum);
793805
newline();
794806
}
807+
if(module.modules) {
808+
processModulesList(module, prefix + "| ");
809+
}
795810
};
796811

797812
const processModulesList = (obj, prefix) => {
798813
if(obj.modules) {
799814
obj.modules.forEach(module => {
800815
colors.normal(prefix);
801-
if(module.id < 1000) colors.normal(" ");
802-
if(module.id < 100) colors.normal(" ");
803-
if(module.id < 10) colors.normal(" ");
804-
colors.normal("[");
805-
colors.normal(module.id);
806-
colors.normal("]");
807816
const name = module.name || module.identifier;
817+
let contentPrefix = prefix + " ";
818+
if(typeof module.id === "string" || typeof module.id === "number") {
819+
contentPrefix += " ";
820+
if(module.id < 1000) colors.normal(" ");
821+
if(module.id < 100) colors.normal(" ");
822+
if(module.id < 10) colors.normal(" ");
823+
colors.normal("[");
824+
colors.normal(module.id);
825+
colors.normal("]");
826+
if(name !== module.id)
827+
colors.normal(" ");
828+
}
808829
if(name !== module.id) {
809-
colors.normal(" ");
810830
colors.bold(name);
811831
}
812832
processModuleAttributes(module);
813833
newline();
814-
processModuleContent(module, prefix + " ");
834+
processModuleContent(module, contentPrefix);
815835
});
816836
if(obj.filteredModules > 0) {
817837
colors.normal(prefix);

lib/optimize/ConcatenatedModule.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ class ConcatenatedModule extends Module {
186186
// Info from Optimization
187187
this.used = rootModule.used;
188188
this.usedExports = rootModule.usedExports;
189-
this.optimizationBailout = rootModule.optimizationBailout;
190189

191190
// Info from Build
192191
this.buildInfo = {

lib/optimize/ModuleConcatenationPlugin.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ class ModuleConcatenationPlugin {
8787

8888
relevantModules.push(module);
8989

90+
const chunks = module.getChunks();
91+
9092
// Module must not be the entry points
91-
if(module.getChunks().some(chunk => chunk.entryModule === module)) {
93+
if(chunks.some(chunk => chunk.entryModule === module)) {
9294
setBailoutReason(module, "Module is an entry point");
9395
continue;
9496
}
9597

98+
// Module must be in any chunk (we don't want to do useless work)
99+
if(chunks.length === 0) {
100+
setBailoutReason(module, "Module is not in any chunk");
101+
continue;
102+
}
103+
96104
// Module must only be used by Harmony Imports
97105
const nonHarmonyReasons = module.reasons.filter(reason => !reason.dependency || !(reason.dependency instanceof HarmonyImportDependency));
98106
if(nonHarmonyReasons.length > 0) {

schemas/WebpackOptions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,6 +1507,10 @@
15071507
"type": "boolean",
15081508
"description": "add built modules information"
15091509
},
1510+
"nestedModules": {
1511+
"type": "boolean",
1512+
"description": "add information about modules nested in other modules (like with module concatenation)"
1513+
},
15101514
"children": {
15111515
"type": "boolean",
15121516
"description": "add children information"

test/statsCases/commons-plugin-issue-4980/expected.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Child
88
runtime.js 7.03 KiB 2 [emitted] runtime
99
[./constants.js] 87 bytes {1} [built]
1010
[./entry-1.js] ./entry-1.js + 2 modules 190 bytes {0} [built]
11+
| ./entry-1.js 67 bytes [built]
12+
| ./submodule-a.js 59 bytes [built]
13+
| ./submodule-b.js 59 bytes [built]
1114
Child
1215
Hash: 01bd4246a474bfd828f8
1316
Time: Xms
@@ -16,4 +19,7 @@ Child
1619
vendor.054b9142e1966b5880c5.js 619 bytes 1 [emitted] vendor
1720
runtime.js 7.03 KiB 2 [emitted] runtime
1821
[./constants.js] 87 bytes {1} [built]
19-
[./entry-2.js] ./entry-2.js + 2 modules 197 bytes {0} [built]
22+
[./entry-2.js] ./entry-2.js + 2 modules 197 bytes {0} [built]
23+
| ./entry-2.js 67 bytes [built]
24+
| ./submodule-a.js 59 bytes [built]
25+
| ./submodule-c.js 66 bytes [built]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[0] ./index.js + 2 modules 119 bytes {0} [built]
2+
| ./index.js 46 bytes [built]
3+
| ModuleConcatenation bailout: Module is an entry point
4+
| ./node_modules/pmodule/a.js 49 bytes [built]
5+
| ./node_modules/pmodule/aa.js 24 bytes [built]
6+
[1] ./node_modules/pmodule/index.js 63 bytes [built]
7+
ModuleConcatenation bailout: Module is not in any chunk
8+
[2] ./node_modules/pmodule/b.js 49 bytes [built]
9+
ModuleConcatenation bailout: Module is not in any chunk
10+
[3] ./node_modules/pmodule/c.js 49 bytes [built]
11+
ModuleConcatenation bailout: Module is not in any chunk
12+
[4] ./node_modules/pmodule/bb.js 24 bytes [built]
13+
ModuleConcatenation bailout: Module is not in any chunk
14+
[5] ./node_modules/pmodule/cc.js 24 bytes [built]
15+
ModuleConcatenation bailout: Module is not in any chunk
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { a } from "pmodule";
2+
3+
console.log(a);

test/statsCases/concat-and-sideeffects/node_modules/pmodule/a.js

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

test/statsCases/concat-and-sideeffects/node_modules/pmodule/aa.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/concat-and-sideeffects/node_modules/pmodule/b.js

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

test/statsCases/concat-and-sideeffects/node_modules/pmodule/bb.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/concat-and-sideeffects/node_modules/pmodule/c.js

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

test/statsCases/concat-and-sideeffects/node_modules/pmodule/cc.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/concat-and-sideeffects/node_modules/pmodule/index.js

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

test/statsCases/concat-and-sideeffects/node_modules/pmodule/package.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
mode: "production",
3+
entry: "./index",
4+
stats: {
5+
all: false,
6+
modules: true,
7+
nestedModules: true,
8+
optimizationBailout: true
9+
}
10+
};

test/statsCases/parse-error/expected.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Asset Size Chunks Chunk Names
22
main.js 3.09 KiB 0 main
33
[0] ./index.js + 1 modules 35 bytes {0} [built]
4+
| ./index.js 15 bytes [built]
5+
| ./a.js 15 bytes [built]
46
[1] ./b.js 169 bytes {0} [built] [failed] [1 error]
57

68
ERROR in ./b.js

test/statsCases/scope-hoisting-multi/expected.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ Child
2020
[1] ./vendor.js 25 bytes {5} [built]
2121
ModuleConcatenation bailout: Module is an entry point
2222
[2] ./common.js + 1 modules 62 bytes {3} {4} [built]
23+
| ./common.js 37 bytes [built]
24+
| ./common2.js 25 bytes [built]
2325
[3] ./common_lazy.js 25 bytes {1} {2} [built]
2426
[4] ./first.js + 1 modules 248 bytes {4} [built]
25-
ModuleConcatenation bailout: Module is an entry point
2627
ModuleConcatenation bailout: Cannot concat with ./common.js
2728
ModuleConcatenation bailout: Cannot concat with ./vendor.js (<- Module is an entry point)
29+
| ./first.js 207 bytes [built]
30+
| ModuleConcatenation bailout: Module is an entry point
31+
| ./module_first.js 31 bytes [built]
2832
[5] ./lazy_shared.js 31 bytes {0} [built]
2933
ModuleConcatenation bailout: Module is referenced from these modules with unsupported syntax: ./first.js (referenced with import()), ./second.js (referenced with import())
3034
[6] ./second.js 177 bytes {3} [built]

0 commit comments

Comments
 (0)