webpack-contrib / webpack-bundle-analyzer

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

Incorrect size when using Webpack's `BannerPlugin` #598

Closed guilhermesimoes closed 1 year ago

guilhermesimoes commented 1 year ago

Issue description

Adding the following BannerPlugin to a build:

new BannerPlugin({
  banner: 'console.log("hello world");',
  raw: true,
}),

changes the results of webpack-bundle-analyzer.

Without using BannerPlugin: Screenshot 2023-05-22 at 16 37 09

Using BannerPlugin: Screenshot 2023-05-22 at 16 38 18 These results are wrong (just look at the size of src).

Do note that this happens with an entry point that is a Worker, I did not verify if this also happens with other kinds of entry points.

Technical info


  System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.99 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.12.1 - ~/.nvm/versions/node/v18.12.1/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.12.1/bin/yarn
    npm: 8.19.2 - ~/.nvm/versions/node/v18.12.1/bin/npm
  npmPackages:
    copy-webpack-plugin: 9.1.0 => 9.1.0 
    fork-ts-checker-webpack-plugin: 6.3.3 => 6.3.3 
    html-webpack-plugin: 5.5.0 => 5.5.0 
    terser-webpack-plugin: 5.3.6 => 5.3.6 
    webpack: 5.75.0 => 5.75.0 
    webpack-bundle-analyzer: 4.8.0 => 4.8.0 
    webpack-cli: 4.8.0 => 4.8.0 
    webpack-dev-server: 4.3.0 => 4.3.0 
    webpack-glsl-loader: 1.0.1 => 1.0.1 
    webpack-license-plugin: 4.2.2 => 4.2.2 
    webpack-retry-chunk-load-plugin: 2.2.0 => 2.2.0 
    webpack-stats-plugin: 1.0.3 => 1.0.3 

Debug info

I use this module as a plugin, without any options:

new BundleAnalyzerPlugin()
valscion commented 1 year ago

What did you expect to have? Do note that the "without BannerPlugin" image does not show what the size of src is

guilhermesimoes commented 1 year ago

You can see on the second image that a lot of code from src is simply missing.

The expected parsed size is something like 450kB.

valscion commented 1 year ago

Hmm yeah, I think the way we parse bundles requires the first thing in the bundle to be the start of a webpack module. So using something like BannerPlugin would indeed break things.

Source: https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/v4.8.0/src/parseUtils.js

If this is the case, then this turns to a feature request to support BannerPlugin. You can open a feature request over at the Discussions "Ideas" category here: https://github.com/webpack-contrib/webpack-bundle-analyzer/discussions/categories/ideas

guilhermesimoes commented 1 year ago

Done! Here's the feature request: https://github.com/webpack-contrib/webpack-bundle-analyzer/discussions/601

I'm closing this issue then. Thank you for your guidance 🙏

valscion commented 1 year ago

Thank you for opening the feature request ☺️. It's easier to triage issues when feature requests are in discussions instead.