I want to minify all .html
files in a folder (and any folders within) using npm run
script. Ideally, all .html
files should be overwritten (if that's not possible, a new folder is acceptable). It is assumed that there will be non-HTML files in the input folder.
npm library minimize
works only on per-file but not on folders.
Another npm library html-minifier
does accept folder as input, but fails if there are any non-HTML files present in the input folder:
html-minifier --input-dir ./test1 --output-dir ./test2 --html-5 --collapse-whitespace
I need this to minify my static website's HTML files.
Since posting original question here on SO, html-minifier
added the feature to ignore the non-HTML files. Now you can set directories and html-minifier
won't error-out when it encounters non-HTML files.
Usage example, taken from my working npm task:
html-minifier --input-dir ./public --output-dir ./public --collapse-whitespace --file-ext html
Let's minify all our static websites' HTML files now!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With