Open ryan-roemer opened 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.
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.
The stats object has the source and source size of the original unprocessed source.
Task: get the final processed size if possible.
Ideas:
DuplicatesPlugin
, see if we can do a compiler hook to late grab sources and updatesize
fields in the original stats object./cc @exogen