我正在使用 https://github.com/jney/grunt-htmlcompressor压缩 HTML 文件。但这需要我手动输入所有我想要缩小的 HTML 文件:
grunt.initConfig({
htmlcompressor: {
compile: {
files: {
'dest/index.html': 'src/index.html'
},
options: {
type: 'html',
preserveServerScript: true
}
}
}
});
有没有办法指定我要缩小整个文件夹(和子文件夹)的所有 HTML 文件?
或者,如果这个 html 压缩器是有限的,您是否知道执行此 HTML mification 的不同 npm 包?
最佳答案
glob pattern默认情况下应该允许任何 grunt 任务。然后只需使用 dynamic files把每一个都 build 到你的目的地
代替:
files: {
'dest/index.html': 'src/index.html'
},
选择:
files: [
{
expand: true, // Enable dynamic expansion.
cwd: 'src/', // Src matches are relative to this path.
src: ['**/*.html'], // Actual pattern(s) to match.
dest: 'dest/', // Destination path prefix.
},
],
就我推荐的另一个插件而言 grunts contrib version因为它更常见并且由 grunt 团队维护。
关于html - Gruntfile 缩小文件夹的所有 HTML 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22576841/