我在我的grunt构建开始时运行grunt-contrib-clean任务来清除目标目录。我还想在最后运行另一个干净的任务来做一些工作。
module.exports = function (grunt) {
grunt.initConfig({
clean: {
options: { force: true },
all: {
//..
}
},
//Other tasks
clean2: {
options: { force: true },
all: {
//..
}
}
});
grunt.registerTask('default', ['']);
grunt.registerTask('build', ['clean', 'clean2']);
grunt.loadNpmTasks('grunt-contrib-clean');
};
如何使用不同的参数两次调用clean任务?
答案 0 :(得分:3)
你已经非常接近了。查看grunt-contrib-clean的文档,看来你应该看看他们的"long" usage example。
我相信您只需将clean
配置为:
clean: {
target: {
src: "path/to/target",
options: { force: true },
all: {
//..
}
},
otherFolder: {
src: "path/to/other/folder",
options: { force: true },
all: {
//..
}
}
}
然后,您可以通过引用您想要的clean
来注册任务:
grunt.registerTask('build', ['clean:target', 'clean:otherFolder']);
作为旁注:我会仔细检查你是否真的需要使用force
选项。 Per the documentation:谨慎使用。