【发布时间】:2013-07-08 06:01:03
【问题描述】:
我的 Gruntfile 重复了"files",在相同任务的两个目标dist 和dev 之间共享。这是一个仅包含 Stylus 问题的示例:
"use strict";
module.exports = function (grunt) {
grunt.loadNpmTasks("grunt-contrib-stylus");
grunt.initConfig({
stylus: {
dist: {
files: { "www/bundle.css": ["stylus/*.styl"] },
options: { compress: true, linenos: false }
},
dev: {
files: { "www/bundle.css": ["stylus/*.styl"] },
options: { compress: false, linenos: true }
}
}
});
grunt.registerTask("dev", ["stylus:dev"]);
grunt.registerTask("prod", ["stylus:prod"]);
};
有没有办法将文件配置上移一个级别,这样我就不必在两个目标中重复它?
【问题讨论】:
-
你为什么不能说 "var myFiles = { "www/bundle.css": ["stylus/*.styl"] };"在 grunt.initConfig 之前,然后在需要的地方说“files:myFiles”?它只是一个对象,不是吗?我相信您也可以编写一个将文件属性注入每个对象的函数,但是...我的意思是 DRY,但在某些时候您会为了一点方便而牺牲很多复杂性。
-
这是这个问题的重复:stackoverflow.com/questions/15927368
标签: javascript build gruntjs