webpack-contrib / webpack-bundle-analyzer

Webpack plugin and CLI utility that represents bundle content as convenient interactive zoomable treemap
MIT License
12.58k stars 487 forks source link

Missing `parsed` module sizes and `node_modules` stats #466

Closed oprav closed 3 years ago

oprav commented 3 years ago

Issue description

While migrating from webpack@3 + webpack-bundle-analyzer@3 to webpack@5.51.1 + webpack-bundle-analyzer@4.4.2 I noticed that HTML report doesn't seem to display parsed sizes of bundled modules anymore. It also looks like bundled node_modules's stats are not displayed when switching into parsed treemap view.

Screenshot 2021-09-16 at 20 45 41

Notes: This might be related to https://github.com/webpack-contrib/webpack-bundle-analyzer/issues/327 although I'm not totally sure since #327 mentions issues for edge cases only.

I have created a minimal repro setup demonstrating allegedly missing stats: https://github.com/oprav/wba-webpack5-repro

Not sure if this is expected - I noticed that this condition doesn't seem to be met when attempting to generate report for my bundle: https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/f83c46a1159ad96cd8ad02562766ed9807ceb205/src/parseUtils.js#L43

i.e. there are no modules parsed into walk.locations: https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/f83c46a1159ad96cd8ad02562766ed9807ceb205/src/parseUtils.js#L145

Technical info

System:
    OS: macOS 10.15.7
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 1.65 GB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.18.4 - ~/.nvm/versions/node/v12.18.4/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v12.18.4/bin/yarn
    npm: 6.14.6 - ~/.nvm/versions/node/v12.18.4/bin/npm
  npmPackages:
    webpack: ^5.52.1 => 5.52.1 
    webpack-bundle-analyzer: ^4.4.2 => 4.4.2 
    webpack-cli: ^4.8.0 => 4.8.0 

Debug info

How do you use this module? As CLI utility or as plugin?

Plugin

If CLI, what command was used? (e.g. webpack-bundle-analyzer -O path/to/stats.json)

If plugin, what options were provided? (e.g. new BundleAnalyzerPlugin({ analyzerMode: 'disabled', generateStatsFile: true }))

{
    openAnalyzer: false,
    reportFilename: `report.html`,
    analyzerMode: 'static',
 }

What other Webpack plugins were used?

None (for repro code)

It would be nice to also attach webpack stats file. It can be generated using these options:

new BundleAnalyzerPlugin({
  analyzerMode: 'disabled',
  generateStatsFile: true,
  // Excludes module sources from stats file so there won't be any sensitive data
  statsOptions: { source: false }
})

stats.json will be created in Webpack bundle output directory.

File link: https://github.com/oprav/wba-webpack5-repro/blob/master/output/stats.json

valscion commented 3 years ago

The main.js appears to be a concatenated module in your screenshot so we do not have any size information to show how its contents are split.

Are you able to see the parsed size of the main.js file, though?

This module concatenation is the result of webpack 5 enabling module concatenation by default. See:

oprav commented 3 years ago

Thanks for a quick reply.

Are you able to see the parsed size of the main.js file, though?

No, main.js doesn't report parsed size:

Screenshot 2021-09-17 at 11 32 08

main.js + 2 modules does show it although its value appears to be the size of entire bundle (including node_modules):

Screenshot 2021-09-17 at 11 32 16

I tried disasbling concatenateModules behaviour, but it doesn't seem to have any effect.

valscion commented 3 years ago

main.js + 2 modules does show it although its value appears to be the size of entire bundle (including node_modules):

Yes so it works as expected :) there's nothing we can do about this as the bundle no longer contains module boundaries

oprav commented 3 years ago

So in case module boundaries are not erased (i.e. concatenateModules: false) - parsed sizes should be calculated? In case they should - it doesn't happen in the repro setup linked in the issue description.

valscion commented 3 years ago

If the visualizer shows the (concatenated) text, it means that webpack has concatenated the modules for some reason. Further analysis on why that happens is outside the scope of webpack-bundle-analyzer ☺️