kangax / html-minifier

Javascript-based HTML compressor/minifier (with Node.js support)
http://kangax.github.io/html-minifier/
MIT License
4.94k stars 571 forks source link

minifying only html css and js files #1031

Open stephaniedavidson opened 5 years ago

stephaniedavidson commented 5 years ago

Getting an error when I run html-minifier and there is an image anywhere. I'd like to limit it to certain file types, say html, css, and js.

Seems weird to break it into separate scripts, can I combine the flags, or exclude images? Can't find any documentation.

My npm script:

"minify": "html-minifier --input-dir ./public --output-dir ./public --collapse-whitespace --file-ext html",

what I want is something like..

"minify": "html-minifier --input-dir ./public --output-dir ./public --collapse-whitespace --file-ext html --file-ext css --file-ext js",

but that doesn't work

ryo-hisano commented 5 years ago

@stephaniedavidson

I think that it is for reducing the weight of HTML as an application of "HTML minifier".

If you use the command below,--file-ext option does not want to be the .js file set last. You can not specify an array in the --file-ext option, nor do you have an option to exclude the specified extension, By setting --file-ext html, you should avoid errors that are executed on the image file, I think it is better to use "cssnano" for lighter CSS and "UglifyJS" for lightweight JavaScript.