gpt4 book ai didi

javascript - 如何在 grunt initConfig 函数中多次运行任务

转载 作者:行者123 更新时间:2023-11-28 19:30:08 24 4
gpt4 key购买 nike

我在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com