html-critical-webpack-plugin
html-critical-webpack-plugin copied to clipboard
Have HtmlCriticalWebpack contribute critical's changes back to the compilation
Summary
Currently, this plugin wraps critical so that it can be called as part of a webpack build lifecycle. By design though, critical only reads and writes to the filesystem. In this way, HtmlCriticalWebpackPlugin acts more in a capacity of that of a post-build step / action.
Per the discussion in #21, and that this plugin assumes the presence of HtmlWebpackPlugin, it might be a nice touch if this plugin could get the result of calling critical, and apply that change to the compilation directly instead, but without any filesystem I / O.
Benefits
- Keeps the build process entirely in the realm of webpack. This is especially important to avoid any potential race conditions with the webpack build (in memory vs. I/O)
- In memory might be more performant
- No need to "post-process" the build
- Maintain consistent behaviors / expectation of how a webpack plugin might be expected to work in general
Initial Thoughts
critical's API expects an entry point file and so (without having looked at it) I'm not sure how that would work with how webpack manages the compilation (bundled assets) in memory; be it AST, string, Buffer, something else?. Same thing for the output file I imagine.
I think it might come down to being able to tap into critical's API enough to be able to get all its business logic, but without the I/O. 🤔
This would definitely be an improvement if it can be achieved.