Skip to content

Commit 0188312

Browse files
authored
Merge pull request #386 from ZKHelloworld/fix-no-name-asset
Fix assets without name causing analyze failure
2 parents 9624991 + 493c30c commit 0188312

5 files changed

Lines changed: 513 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ _Note: Gaps between patch versions are faulty, broken or test releases._
1313
## UNRELEASED
1414

1515
<!-- Add changelog entries for new changes under this section -->
16+
* **Bug Fix**
17+
* Fix `non-asset` assets causing analyze failure. ([##385](https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/385) by [@ZKHelloworld](https://github.com/ZKHelloworld))
1618

1719
## 4.1.0
1820

src/analyzer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ function getViewerData(bundleStats, bundleDir, opts) {
4949

5050
// Picking only `*.js or *.mjs` assets from bundle that has non-empty `chunks` array
5151
bundleStats.assets = _.filter(bundleStats.assets, asset => {
52+
// Filter out non 'asset' type asset if type is provided (Webpack 5 add a type to indicate asset types)
53+
if (asset.type && asset.type !== 'asset') {
54+
return false;
55+
}
56+
5257
// Removing query part from filename (yes, somebody uses it for some reason and Webpack supports it)
5358
// See #22
5459
asset.name = asset.name.replace(FILENAME_QUERY_REGEXP, '');

test/analyzer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ describe('Analyzer', function () {
155155
expect(chartData).to.containSubset(require('./stats/with-modules-in-chunks/expected-chart-data'));
156156
});
157157

158+
it('should support stats files with non-asset asset', async function () {
159+
generateReportFrom('with-non-asset-asset/stats.json');
160+
await expectValidReport({bundleLabel: 'bundle.js'});
161+
});
162+
158163
describe('options', function () {
159164
describe('title', function () {
160165
it('should take the --title option', async function () {

test/stats/with-non-asset-asset/bundle.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.

0 commit comments

Comments
 (0)