Search code examples
javascriptnode-modulesbrowserify

How to use html-minifier module in browser?


I just want to use function from html-minifier in the browser.

I have tried using Browserify to make bundle using these commands: browserify -r html-minifier -o html-minifier.js browserify -r html-minifier -s htmlMinifier -o html-minifier.js

Also tried importing as module and script but it gives require.resolve is not a function

Even tried CDNs like Skypack

This issue provides a pre-built minified bundle which works but I need to create the bundle myself for latest version after some changes.


Solution

  • https://github.com/kangax/html-minifier/blob/gh-pages/Gruntfile.js is the Gruntfile used to generate the solution you point to. The Gruntfile uses browserify but with a lot of specific settings. Given that html-minifier hasn't seen a new version published in 4 years and the Gruntfile is about 4 years old, it seems likely that it will work to build the browser-based html-minifier for you.