npm脚本:需要缩小文件夹(和子文件夹)中的所有HTML文件 [英] npm scripts: need to minify all HTML files in folder (and subfolders)

查看:104
本文介绍了npm脚本:需要缩小文件夹(和子文件夹)中的所有HTML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 npm run 脚本缩小文件夹(以及其中的所有文件夹)中的所有 .html 文件。理想情况下,应覆盖所有 .html 文件(如果不可能,则可以接受新文件夹)。假设输入文件夹中将包含非HTML文件。

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 最小化仅适用于每个文件但不在文件夹上。

npm library minimize works only on per-file but not on folders.

另一个npm库 html-minifier 确实接受文件夹作为输入,但是失败了如果输入文件夹中存在任何非HTML文件:

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

我需要这个缩小我的静态网站的HTML文件。

I need this to minify my static website's HTML files.

推荐答案

由于在SO上发布原始问题, html-minifier 添加了忽略非HTML文件的功能。现在你可以设置目录, html-minifier 在遇到非HTML文件时不会出错。

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.

使用示例,取自我工作的npm任务:

Usage example, taken from my working npm task:

html-minifier --input-dir ./public --output-dir ./public --collapse-whitespace --file-ext html

让我们缩小所有静态网站'现在是HTML文件!

Let's minify all our static websites' HTML files now!

这篇关于npm脚本:需要缩小文件夹(和子文件夹)中的所有HTML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆