Skip to content

Commit

Permalink
Merge pull request #394 from ctavan/fix-webpack-array-config
Browse files Browse the repository at this point in the history
Fix handling of webpack array configs
  • Loading branch information
valscion committed Nov 12, 2020
2 parents d093666 + 303d801 commit d04b767
Show file tree
Hide file tree
Showing 6 changed files with 355 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -14,7 +14,8 @@ _Note: Gaps between patch versions are faulty, broken or test releases._

<!-- Add changelog entries for new changes under this section -->
* **Bug Fix**
* Fix `non-asset` assets causing analyze failure. ([##385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))
* Prevent crashes for bundles generated from webpack array configs. ([#394](https://github.com/webpack-contrib/webpack-bundle-analyzer/pull/394) by [@ctavan](https://github.com/ctavan))
* Fix `non-asset` assets causing analyze failure. ([#385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))

## 4.1.0

Expand Down
2 changes: 1 addition & 1 deletion src/analyzer.js
Expand Up @@ -32,7 +32,7 @@ function getViewerData(bundleStats, bundleDir, opts) {
// Sometimes if there are additional child chunks produced add them as child assets,
// leave the 1st one as that is considered the 'root' asset.
for (let i = 1; i < children.length; i++) {
bundleStats.children[i].assets.forEach((asset) => {
children[i].assets.forEach((asset) => {
asset.isChild = true;
bundleStats.assets.push(asset);
});
Expand Down
12 changes: 12 additions & 0 deletions test/analyzer.js
Expand Up @@ -37,6 +37,18 @@ describe('Analyzer', function () {
});
});

it('should generate report for array webpack.config.js', async function () {
generateReportFrom('with-array-config/stats.json');
const chartData = await getChartData();
expect(chartData).to.have.lengthOf(2);
expect(chartData[0]).to.containSubset({
label: 'config-1-main.js'
});
expect(chartData[1]).to.containSubset({
label: 'config-2-main.js'
});
});

it('should generate report when worker bundles have dynamic imports', async function () {
generateReportFrom('with-worker-loader-dynamic-import/stats.json');
const chartData = await getChartData();
Expand Down
1 change: 1 addition & 0 deletions test/stats/with-array-config/config-1-main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/stats/with-array-config/config-2-main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

338 changes: 338 additions & 0 deletions test/stats/with-array-config/stats.json
@@ -0,0 +1,338 @@
{
"errors": [],
"warnings": [],
"version": "4.44.2",
"hash": "a30aaa779dd06e8979b1a30aaa779dd06e8979b1",
"children": [
{
"errors": [],
"warnings": [],
"hash": "a30aaa779dd06e8979b1",
"time": 105,
"builtAt": 1605088887042,
"publicPath": "",
"outputPath": "/webpack-bundle-analyzer-example/",
"assetsByChunkName": {
"main": "config-1-main.js"
},
"assets": [
{
"name": "config-1-main.js",
"size": 948,
"chunks": [0],
"chunkNames": ["main"],
"info": {},
"emitted": true
}
],
"filteredAssets": 0,
"entrypoints": {
"main": {
"chunks": [0],
"assets": ["config-1-main.js"],
"children": {},
"childAssets": {}
}
},
"namedChunkGroups": {
"main": {
"chunks": [0],
"assets": ["config-1-main.js"],
"children": {},
"childAssets": {}
}
},
"chunks": [
{
"id": 0,
"rendered": true,
"initial": true,
"entry": true,
"size": 20,
"names": ["main"],
"files": ["config-1-main.js"],
"hash": "0e20b5164c4e5cda6fe0",
"siblings": [],
"parents": [],
"children": [],
"childrenByOrder": {},
"modules": [
{
"id": 0,
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 0,
"size": 20,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"issuer": null,
"issuerId": null,
"issuerName": null,
"issuerPath": null,
"profile": {
"factory": 35,
"building": 38
},
"failed": false,
"errors": 0,
"warnings": 0,
"assets": [],
"reasons": [
{
"moduleId": null,
"moduleIdentifier": null,
"module": null,
"moduleName": null,
"type": "single entry",
"userRequest": "./src/index.js",
"loc": "main"
}
],
"usedExports": true,
"providedExports": null,
"optimizationBailout": [
"ModuleConcatenation bailout: Module is not an ECMAScript module"
],
"depth": 0,
"source": "console.log('ABC');\n"
}
],
"filteredModules": 0,
"origins": [
{
"module": "",
"moduleIdentifier": "",
"moduleName": "",
"loc": "main",
"request": "./src/index.js",
"reasons": []
}
]
}
],
"modules": [
{
"id": 0,
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 0,
"size": 20,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"issuer": null,
"issuerId": null,
"issuerName": null,
"issuerPath": null,
"profile": {
"factory": 35,
"building": 38
},
"failed": false,
"errors": 0,
"warnings": 0,
"assets": [],
"reasons": [
{
"moduleId": null,
"moduleIdentifier": null,
"module": null,
"moduleName": null,
"type": "single entry",
"userRequest": "./src/index.js",
"loc": "main"
}
],
"usedExports": true,
"providedExports": null,
"optimizationBailout": [
"ModuleConcatenation bailout: Module is not an ECMAScript module"
],
"depth": 0,
"source": "console.log('ABC');\n"
}
],
"filteredModules": 0,
"logging": {
"webpack.buildChunkGraph.visitModules": {
"entries": [],
"filteredEntries": 2,
"debug": false
}
},
"children": []
},
{
"errors": [],
"warnings": [],
"hash": "a30aaa779dd06e8979b1",
"time": 88,
"builtAt": 1605088887043,
"publicPath": "",
"outputPath": "/webpack-bundle-analyzer-example/",
"assetsByChunkName": {
"main": "config-2-main.js"
},
"assets": [
{
"name": "config-2-main.js",
"size": 948,
"chunks": [0],
"chunkNames": ["main"],
"info": {},
"emitted": true
}
],
"filteredAssets": 0,
"entrypoints": {
"main": {
"chunks": [0],
"assets": ["config-2-main.js"],
"children": {},
"childAssets": {}
}
},
"namedChunkGroups": {
"main": {
"chunks": [0],
"assets": ["config-2-main.js"],
"children": {},
"childAssets": {}
}
},
"chunks": [
{
"id": 0,
"rendered": true,
"initial": true,
"entry": true,
"size": 20,
"names": ["main"],
"files": ["config-2-main.js"],
"hash": "0e20b5164c4e5cda6fe0",
"siblings": [],
"parents": [],
"children": [],
"childrenByOrder": {},
"modules": [
{
"id": 0,
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 0,
"size": 20,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"issuer": null,
"issuerId": null,
"issuerName": null,
"issuerPath": null,
"profile": {
"factory": 29,
"building": 9
},
"failed": false,
"errors": 0,
"warnings": 0,
"assets": [],
"reasons": [
{
"moduleId": null,
"moduleIdentifier": null,
"module": null,
"moduleName": null,
"type": "single entry",
"userRequest": "./src/index.js",
"loc": "main"
}
],
"usedExports": true,
"providedExports": null,
"optimizationBailout": [
"ModuleConcatenation bailout: Module is not an ECMAScript module"
],
"depth": 0,
"source": "console.log('ABC');\n"
}
],
"filteredModules": 0,
"origins": [
{
"module": "",
"moduleIdentifier": "",
"moduleName": "",
"loc": "main",
"request": "./src/index.js",
"reasons": []
}
]
}
],
"modules": [
{
"id": 0,
"identifier": "/webpack-bundle-analyzer-example/src/index.js",
"name": "./src/index.js",
"index": 0,
"index2": 0,
"size": 20,
"cacheable": true,
"built": true,
"optional": false,
"prefetched": false,
"chunks": [0],
"issuer": null,
"issuerId": null,
"issuerName": null,
"issuerPath": null,
"profile": {
"factory": 29,
"building": 9
},
"failed": false,
"errors": 0,
"warnings": 0,
"assets": [],
"reasons": [
{
"moduleId": null,
"moduleIdentifier": null,
"module": null,
"moduleName": null,
"type": "single entry",
"userRequest": "./src/index.js",
"loc": "main"
}
],
"usedExports": true,
"providedExports": null,
"optimizationBailout": [
"ModuleConcatenation bailout: Module is not an ECMAScript module"
],
"depth": 0,
"source": "console.log('ABC');\n"
}
],
"filteredModules": 0,
"logging": {
"webpack.buildChunkGraph.visitModules": {
"entries": [],
"filteredEntries": 2,
"debug": false
}
},
"children": []
}
]
}

0 comments on commit d04b767

Please sign in to comment.