咕噜。以编程方式将并行文件夹中的相应文件与concat合并 [英] Grunt. Programmatically merge corresponding files in parallel folders with concat
问题描述
这是我在StackOverflow上的第一篇文章!:DI mean ... ever!
that's my first post on StackOverflow!:D I mean... ever!
无论如何...我找不到任何明确的答案,也许我错过了一些非常明显的东西。我也是Grunt的新手。我正在寻找一种方法来在几行代码中将并行css文件合并到两个不同的文件夹中。因此,对每一对文件做一个更好的解决方案:
Anyway... I couldn't find any clear answer to this, and maybe I'm missing something really obvious. I'm really new to Grunt as well. I'm looking for a way to merge parallel css files in two different folders in few lines of code. So a better solution than doing this for each couple of files:
concat : {
options : { separator : '\n' },
css : {
files:{
'<%= pkg.dest %>/app/css/main_blue.css' :
[ 'app/css/base/main_blue.css', 'app/css/extended/main_blue.css' ],
'<%= pkg.dest %>/app/css/main_red.css' :
[ 'app/css/base/main_red.css', 'app/css/extended/main_red.css' ],
'<%= pkg.dest %>/app/css/home.css' :
[ 'app/css/base/home.css', 'app/css/extended/home.css' ],
...
'<%= pkg.dest %>/app/css/.../foo/bar/xx.css' :
['app/css/base/.../foo/bar/xx.css', 'app/css/extended/.../foo/bar/xx.css' ]
...
}
}
}
任何Grunt guru都可以提供帮助吗? :)
Any Grunt guru out there that can help? :)
推荐答案
您可以构建您传递给 grunt.initConfig $ c的配置对象$ c $>动态。
You could build the config object that you pass to grunt.initConfig
dynamically.
var config = {}; // <- your grunt config
var files = ['blue', 'red', 'home'];
for (var i = 0; i < files.length; i++) {
config['concat']['options']['css']['files']['<%= pkg.dest %>/app/css/'+files[i]+'.css'] = [ 'app/css/base/'+files[i]+'.css', 'app/css/extended/'+files[i]+'.css' ];
}
grunt.initConfig(config);
这篇关于咕噜。以编程方式将并行文件夹中的相应文件与concat合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!