我在 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 任务两次?
最佳答案
你已经拥有的已经非常接近了。看看 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 :谨慎使用。
关于javascript - 如何在 grunt initConfig 函数中多次运行任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26991953/