Ale*_*lex 3 html minify gruntjs
我正在使用https://github.com/jney/grunt-htmlcompressor来压缩HTML文件.但它需要我手动输入我想要缩小的所有HTML文件:
grunt.initConfig({
htmlcompressor: {
compile: {
files: {
'dest/index.html': 'src/index.html'
},
options: {
type: 'html',
preserveServerScript: true
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
有没有办法指定我想缩小整个文件夹(和子文件夹)的所有HTML文件?
或者,如果这个html压缩器是有限的,你知道一个不同的npm包来做这个HTML mification吗?
Rya*_*n Q 13
该glob模式应该被允许在默认情况下任何咕噜任务.然后只需使用动态文件将每个文件构建到您的dest
而不是:
files: {
'dest/index.html': 'src/index.html'
},
Run Code Online (Sandbox Code Playgroud)
跟着:
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.
},
],
Run Code Online (Sandbox Code Playgroud)
至于另一个插件,我会推荐grunts contrib版本,因为它更常见并由grunt团队维护.