-
Notifications
You must be signed in to change notification settings - Fork 96
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
vendor isn't added to stats.asssetsByChunkName #23
Comments
Hi, @faceyspacey! Really interesting idea you have here. Sure, if this little change can help AutoDLL better cooperate with your plugin I'll gladly add it. You are more than welcome to send a PR if you like (; |
By the way it seems you cant add to It's unfortunate, but unless I'm missing something, there's nothing we can do. |
Yeah, I'm thinking quite a lot about it lately. I believe that the reason the stats don't know anything about the DLL is that the plugin creates a separate compiler for the DLL and call it before the main compiler. What if I give you access to the DLL compiler? I can expose a plugin hook compiler.plugin('dll-compiler-created', dllCompiler => {
dllCompiler.plugin('emit', (compilation, callback) => {
...
});
}); The catch is that I only compile it when needed, otherwise I read the DLL from the cache (file system) so the stats won't be available in that case. I thought that the stats are not serializable, but then I read in your docs about a plugin called What do think? |
Regarding the hook, it would need to be 100% reliable. Also currently I'm not passed the compiler, just the stats. As for the stats, editing the file created by the I think we have no choice, but to wait until Webpack has an API to write to stats. |
Is there an issue for that or does the webpack team have plans on doing so? |
Hi @faceyspacey! You can use it like this: compiler.plugin('autodll-stats-retrieved', (stats, source) => {
console.log(stats) // stats object
console.log(source) // build / memory / fs
} |
Sweet! |
Let me know if it works for you 😄 |
Hi @asfktz, I've also encountered a problem of vendor files missing in stats object. I wanted to analyze some issues with size of files it produces but unfortunately it relies on the stats being generated by autodllplugin. Is there any way that could be achieved at the moment? Do you have any suggestions on how to use the hook you mentioned in order to append stats from this plugin to the rest of the plugins? |
HI @PeterKottas! How about something like this: class MyPlugin {
apply(compiler) {
let dllStats;
// 'autodll-stats-retrieved' will always be called
// before the main compiler is done
compiler.plugin('autodll-stats-retrieved', (_dllStats, source) => {
// store the dll stats somehow
dllStats = _dllStats
})
compiler.plugin('done', (stats) => {
// now you have access to both
console.log(stats, dllStats)
});
}
} |
Cool, that looks simple enough. I assume this will only output stats specific for the vendors bundle. Or is it actually combining it with the rest of the stats? |
You're right. It's the stats as is. So if you want to merge them, you might what to do the same for the main compilers stats too: compiler.plugin('done', (stats) => {
// now both are serialized
console.log(stats.json(), dllStats);
}); |
Nice one! Would it maybe be worth doing that inside autodll-webpack-plugin? Or in fact, if 'done' is called by webpack only after everything is done, I see how that could be a problem. Maybe you could add some prebuild functionality for this? Although it's hard to say how many people are actually interested in this. |
Hmm.. I can see why you want that, other plugin authors might benefit from abstracting away the fact that there's is actually two different stats, but I feel that I'm not familiar enough with the stats to make the merge inside the plugin. What I can think of is adding another hook right after compiler.plugin('autodll-done', (stats, dllStats) => {
// now you have access to both
console.log(stats, dllStats)
}); |
I see your point. I would look at it myself but I don't have time for it now (might have some around Christmas). I really believe it would be the best if this could be abstracted away so that we have a switch in options "outputStats": boolean which would just spit out the final merged stats. It's true though that merging stats can be tricky. But maybe not, it might surprise us. If you're fine with it, we can open a new issue or reopen this one and hope to find somebody to help, or at least to keep track. |
This would be useful for packages like webpack-flush-chunks which automatically grab assets via the
stats.asssetsByChunkName
hash.By default for example it will grab your
main
andvendor
bundles (along with any rendered dynamic bundles/imports it detects), and insure your dynamic bundles go between yourbootstrap/vendor
andmain
.So essentially this saves you from having to add
<script src="dist/vendor.dll.js"></script>
just in development. One of the premises of the webpack-flush-chunks setup is to help you have as similar a setup in production as development, to make going from development to production as seamless as possible.It's a small thing, I just thought I'd bring it to your attention. Thanks for this package by the way! Super easy.
The text was updated successfully, but these errors were encountered: