在GruntJS中,有没有办法命名由与源文件同名的任务生成的文件。
例如,如果您想将所有.less
文件编译为单个.css
文件,有没有办法像这样做:
files: {
"css/<%= target-filename %>.css": ["less/*.less"]
}
其中<%= target-filename %>
是当前*
文件的.less
的值?
答案 0 :(得分:2)
如果您使用files-array format。您可以指定输出扩展名。请参阅此documentation
这样的事情应该可以解决问题
files: [
{
expand: true, // Enable dynamic expansion.
src: ['less/*.less'], // Actual pattern(s) to match.
dest: 'css/', // Destination path prefix.
ext: '.css', // Dest filepaths will have this extension.
}
]
答案 1 :(得分:0)
您的答案在于building the files object dynamically的文档。
您需要更新代码以使用expand: true
以及使用src
,dest
和cwd
。
假设使用grunt-contrib-less插件的files array format中的示例:
files: [{
expand: true, // The magic switch for processing files 1:1
cwd: '<%= target-less-dir %>/',
src: ['*.less'],
dest: '<%= target-css-dir %>'
}]