Skip to content

Commit 59a750c

Browse files
authored
improvement: Display more detailed module information for concatenated entry modules (#602)
1 parent 37b406d commit 59a750c

File tree

7 files changed

+1077
-2
lines changed

7 files changed

+1077
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1212

1313
## UNRELEASED
1414

15+
* **Improvement**
16+
* Display modules included in concatenated entry modules on Webpack 5 when "Show content of concatenated modules" is checked ([#602](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/602) by [@pgoldberg](https://github.com/pgoldberg))
17+
1518
## 4.8.0
1619

1720
* **Improvement**

src/tree/ConcatenatedModule.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,22 @@ export default class ConcatenatedModule extends Module {
1414
this.fillContentModules();
1515
}
1616

17+
get parsedSize() {
18+
return this.getParsedSize() ?? this.getEstimatedSize('parsedSize');
19+
}
20+
21+
get gzipSize() {
22+
return this.getGzipSize() ?? this.getEstimatedSize('gzipSize');
23+
}
24+
25+
getEstimatedSize(sizeType) {
26+
const parentModuleSize = this.parent[sizeType];
27+
28+
if (parentModuleSize !== undefined) {
29+
return Math.floor((this.size / this.parent.size) * parentModuleSize);
30+
}
31+
}
32+
1733
fillContentModules() {
1834
this.data.modules.forEach(moduleData => this.addContentModule(moduleData));
1935
}
@@ -38,7 +54,8 @@ export default class ConcatenatedModule extends Module {
3854
currentFolder = childFolder;
3955
});
4056

41-
const module = new ContentModule(fileName, moduleData, this);
57+
const ModuleConstructor = moduleData.modules ? ConcatenatedModule : ContentModule;
58+
const module = new ModuleConstructor(fileName, moduleData, this);
4259
currentFolder.addChildModule(module);
4360
}
4461

src/tree/Module.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@ export default class Module extends Node {
2828
}
2929

3030
get parsedSize() {
31-
return this.src ? this.src.length : undefined;
31+
return this.getParsedSize();
3232
}
3333

3434
get gzipSize() {
35+
return this.getGzipSize();
36+
}
37+
38+
getParsedSize() {
39+
return this.src ? this.src.length : undefined;
40+
}
41+
42+
getGzipSize() {
3543
if (!_.has(this, '_gzipSize')) {
3644
this._gzipSize = this.src ? gzipSize.sync(this.src) : undefined;
3745
}

test/analyzer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ describe('Analyzer', function () {
183183
);
184184
});
185185

186+
it('should properly parse webpack 5 bundle with an entry module that is a concatenated module', async function () {
187+
generateReportFrom('webpack-5-bundle-with-concatenated-entry-module/stats.json');
188+
const chartData = await getChartData();
189+
expect(chartData).to.containSubset(
190+
require('./stats/webpack-5-bundle-with-concatenated-entry-module/expected-chart-data')
191+
);
192+
});
193+
186194
it('should support generating JSON output for the report', async function () {
187195
generateJSONReportFrom('with-modules-in-chunks/stats.json');
188196

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(()=>{"use strict";console.log("foo.js"),console.log("bar.js")})(),console.log("baz.js");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"cid": 0, "groups": [{"cid": 1, "concatenated": true, "groups": [{"cid": 2, "gzipSize": 8, "id": 613, "inaccurateSizes": true, "label": "baz.js", "parsedSize": 10, "path": "./entry modules (concatenated)/baz.js", "statSize": 23}, {"cid": 3, "concatenated": true, "groups": [{"cid": 4, "gzipSize": 5, "id": null, "inaccurateSizes": true, "label": "index.js", "parsedSize": 6, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)/index.js", "statSize": 14}, {"cid": 5, "groups": [{"cid": 6, "gzipSize": 12, "id": null, "inaccurateSizes": true, "label": "index.js", "parsedSize": 14, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)/dep/index.js", "statSize": 32}, {"cid": 7, "gzipSize": 25, "id": null, "inaccurateSizes": true, "label": "foo.js", "parsedSize": 29, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)/dep/foo.js", "statSize": 66}, {"cid": 8, "gzipSize": 25, "id": null, "inaccurateSizes": true, "label": "bar.js", "parsedSize": 29, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)/dep/bar.js", "statSize": 66}], "gzipSize": 62, "inaccurateSizes": true, "label": "dep", "parsedSize": 72, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)/dep", "statSize": 164}], "gzipSize": 68, "id": 469, "label": "index.js + 3 modules (concatenated)", "parsedSize": 79, "path": "./entry modules (concatenated)/index.js + 3 modules (concatenated)", "statSize": 178}], "gzipSize": 77, "label": "entry modules (concatenated)", "parsedSize": 90, "path": "./entry modules (concatenated)", "statSize": 201}], "gzipSize": 77, "isAsset": true, "isInitialByEntrypoint": {"app": true}, "label": "app.js", "parsedSize": 90, "statSize": 201}]

0 commit comments

Comments
 (0)