Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ryan-roemer opened this issue Jan 14, 2019 · 2 comments
Open

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

ryan-roemer opened this issue Jan 14, 2019 · 2 comments

Comments

@ryan-roemer
Copy link
Member

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

Task: get the final processed size if possible.

Ideas:

  • For DuplicatesPlugin, see if we can do a compiler hook to late grab sources and update size fields in the original stats object.

/cc @exogen

@exogen
Copy link

exogen commented Jan 15, 2019

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
Copy link

exogen commented Jan 16, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants