npm scripts: need to minify all HTML files in folder (and subfolders)

谁都会走 提交于 2019-12-07 04:51:39

问题


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.


回答1:


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!



来源:https://stackoverflow.com/questions/37363379/npm-scripts-need-to-minify-all-html-files-in-folder-and-subfolders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!