html-critical-webpack-plugin icon indicating copy to clipboard operation
html-critical-webpack-plugin copied to clipboard

Have HtmlCriticalWebpack contribute critical's changes back to the compilation

Open thescientist13 opened this issue 6 years ago • 1 comments

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

  1. 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)
  2. In memory might be more performant
  3. No need to "post-process" the build
  4. 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. 🤔

thescientist13 avatar Jun 27 '18 00:06 thescientist13

This would definitely be an improvement if it can be achieved.

anthonygore avatar Jul 08 '18 04:07 anthonygore