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

Make it easier to access contents of emitted assets #9299

Closed
jimmydief opened this issue Jun 18, 2019 · 5 comments · Fixed by #9318
Closed

Make it easier to access contents of emitted assets #9299

jimmydief opened this issue Jun 18, 2019 · 5 comments · Fixed by #9318

Comments

@jimmydief
Copy link

Feature request

What is the expected behavior?

Prior to futureEmitAssets being added in #8642, it was possible to easily access the final contents of all emitted assets at stats.compilation.assets.

What is motivation or use case for adding/changing the behavior?

This was useful for tracking the size of our bundled assets to avoid unintentional bundle size regressions. While size is still exposed on SizeOnlySource, it's now harder to get access to the actual contents in order to track gzip/brotli/etc. size. Reading in the final emitted files from the file system would work fine but is harder than it probably should be as various plugins like MiniCssExtractPlugin support different public paths for different asset types.

How should this be implemented in your opinion?

Including the location of the emitted asset as part of the asset stats would make things easier. Perhaps this is already available somewhere but I've been unable to find it if so.

Are you willing to work on this yourself?
Yes.

@sokra
Copy link
Member

sokra commented Jun 18, 2019

The publicPath doesn't matter here.

The key in compilation.assets is the output filename in the compilation.outputPath.

@sokra
Copy link
Member

sokra commented Jun 18, 2019

But it probably makes sense to add a Hook which allows to introspect the in-memory file content just after it was emitted to measure i. e. gzip size, etc.

You could add a hook just before this line

callback();

i. e. this.hook.assetEmitted.callAsync(file, content, callback)

and similar here

this.outputFileSystem.writeFile(targetPath, content, callback);

@sokra
Copy link
Member

sokra commented Jun 18, 2019

Send a PR

@jamesgeorge007
Copy link
Member

@sokra I would take this up 👍

@jimmydief
Copy link
Author

Thanks, I meant the output path and not public path. Joining with the output path from the output options did end up working for my use case, will leave the issue open to track that enhancement.

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

Successfully merging a pull request may close this issue.

4 participants