我的任务如下:
htmlmin : {
dist : {
options : {
removeComments : true,
collapseWhitespace : true
},
files : {
'index.html' : 'index-src.html'
}
}
},
当我的网站上只有一个 html 文件时,这可以正常工作,因此会将 index-src.html
处理为缩小的 index.html
。
如果我还有 100 个其他 html
文件要处理怎么办?我不想在我的 gruntfile 中手动列出它们。
我如何抽象文件名并告诉 grunt 将我的 src 文件缩小为相应的生产文件?就我而言,它们是:
源文件是[name]-src.html
生产文件是 [name].html
我猜这只是语法问题,但我不知道该写什么。 谢谢! :)
最佳答案
请参阅Globbing Patterns Grunt 文档的部分。
我相信您只需将参数文件对象更改为:
'index.html':'*-src.html'
更新
重新阅读您的问题,我意识到您需要对动态源文件名和目标文件名进行一对一文件转换。
请参阅Building the files object dynamically
我还没有在我的项目中使用它,但语法看起来很简单。您可能需要将 src 与生产命名约定更改为基于文件夹的约定。
/source/name.html
(源文件夹)/build/name.html
(目标文件夹)
示例
files: [
{
expand: true, // Enable dynamic expansion.
cwd: 'source/', // Src matches are relative to this path.
src: ['*-src.html'], // Actual pattern(s) to match.
dest: 'build/', // Destination path prefix.
ext: '.html', // Dest filepaths will have this extension.
extDot: 'first' // Extensions in filenames begin after the first dot
}
]
关于javascript - 咕噜 htmlmin : don't specify filename in the gruntfile. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25742448/