Consider using @minify-html
Hello :wave:
I've been working on an HTML minifier that is 10X faster than html-minifier while being more effective. It's written in Rust but is available for Node.js as a package (npm i hyperbuild) using native bindings. It also natively binds to esbuild for very fast JS minification (100X faster than terser).
You can see the project and more details here, which goes into the complex minification strategy. It's super easy to use, has TS typings, and has been extensively tested with fuzzing.
Let me know if there's interest in using this for html-webpack-plugin; I can help integrate or alleviate any issues that arise. Also happy to add overlooked or friendliness features currently missing. Thanks!
Hey
👋 thanks for your work that looks really promising - downloading a 230 MB is very much to process 5kb text files..
The html-webpack-plugin was downloaded 250.000.000 times last year. That would be 57.500 TerraByte on top if we go for your plugin. Most CI-CDs use caching but there are still a lot of them which will download your package on every run. So if the download takes slightly longer but the processing is slightly faster it might not help much.
I was also wondering why you didn’t give the module a name which is easier to understand on first glance e.g. html-minifier-rust
If I read it correct it has trouble parsing invalid markup would probably break a lot of people’s build which generate templates for e.g. php or jsp
But still - cool work! Right now I would like wait until it becomes a little bit more mature :) I hope you understand that
Thanks for the reply, and great points :smile:
The html-webpack-plugin was downloaded 250.000.000 times last year. That would be 57.500 TerraByte on top if we go for your plugin. Most CI-CDs use caching but there are still a lot of them which will download your package on every run. So if the download takes slightly longer but the processing is slightly faster it might not help much.
Good point, unfortunately this is due to Neon's lack of support for N-API so far, so builds have to be included for each Node.js version and platform. I will probably revert to using online platform-specific downloads at install time like what esbuild does.
I was also wondering why you didn’t give the module a name which is easier to understand on first glance e.g. html-minifier-rust
Legacy decision, as it started off being a preprocessor as well for HTML files. Will rename once I get it polished.
If I read it correct it has trouble parsing invalid markup would probably break a lot of people’s build which generate templates for e.g. php or jsp
Good point, will look to add this feature; right now it's mostly a pure HTML minifier.
It would be tricky to process <?php blocks, as it seems it would require understanding and parsing PHP syntax, like <?php echo '<?php ?>'; ?>.
But still - cool work! Right now I would like wait until it becomes a little bit more mature :) I hope you understand that
Yeah no worries, it's only on version 0.2 right now :smiley: Will focus more on Node.js ergonomics for the next few versions :+1:
Just an update: renamed the project to minify-html and the npm package is now only 20 KB. It only fetches the platform-specific binary, which I did some measuring:
- core (HTML only): 2 MB, smaller than
node_moduleswhen installinghtml-minifier - js-esbuild (HTML + JS): 9 MB, same size as the
esbuildpackage (but with free HTML minifier :smiley:)
Wow that's impressive! :)
I'll take a look tonight
Any news on this one?
How about using https://github.com/webpack-contrib/html-minimizer-webpack-plugin to define a custom minify function?
Then remove htmlWebpackPlugin.options.minify ...
Yes, it should be implemented on html-minimizer-webpack-plugin side, I think in future we remove HTML minification here in favor of html-minimizer-webpack-plugin, because it is more flexible and allow to compress all HTML assets, not only from html-webpack-plugin, I will add @minify-html support to html-minimizer-webpack-plugin soon