FormidableLabs / inspectpack

An inspection tool for Webpack frontend JavaScript bundles.
MIT License
592 stars 20 forks source link

Feature: Get "final" processed code source size. #102

Open ryan-roemer opened 5 years ago

ryan-roemer commented 5 years ago

The stats object has the source and source size of the original unprocessed source.

Task: get the final processed size if possible.

Ideas:

/cc @exogen

exogen commented 5 years ago

As a last resort, could it work using source maps if those were enabled for this feature? Then for each file we could add up all the source mapping [start, end] positions and in theory the result should be the effective output size of the module.

Considering how slow/big those are though, might be better to just find a stable way to parse the webpack output again.

exogen commented 5 years ago

I started trying to do this by parsing the resulting bundle with Acorn, got it working, then checked out what webpack-bundle-analyzer does. It pretty much does exactly what I had in mind: try a few recognized AST patterns (for various combinations of webpack + plugins) to figure out where the module function definitions start and stop: https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/master/src/parseUtils.js

So looks like its parsed numbers are potentially correct, although I swear I've seen it get tree-shaken modules wrong before.

Maybe we could import that? Seems likely to be maintained.