如何同时运行两个grunt监视任务 [英] How to run two grunt watch tasks simultaneously
问题描述
是否可以同时运行两个监视任务?
据我所知,我可以在 watch 设置中执行任意数量的任务只需启动 grunt watch ,它就会像所有人一样观看它。
...
watch:{
A:{
files:js / dev / ** / *。coffee,
tasks:[coffee,requirejs]
},
B:{
files:js / dev / ** / *。coffee,
tasks:[coffee]
},
C:{
files:js / dev / ** / *。html,
tasks:[copy]
}
}
...
...但我不需要这个。我只想为开发和生产制定不同的任务。正如你所猜测的那样, A (制作)和 B (开发)之间的唯一区别是缩小和拼接。我不需要同时启动 A 和 B 任务。 首先,我带着这个想法
grunt.registerTask(prod,[watch:A,watch:C]);
grunt.registerTask(dev,[watch:B,watch:C]);
但这没有奏效。只是第一个监视任务正在工作( C 从来没有工作)。是否有可能做我想做的事?
我发现使用 grunt-concurrent 工作:
concurrent:{
options:{
logConcurrentOutput:true
},
prod:{
tasks:[watch:A,watch: C]
},
dev:{
tasks:[watch:B,watch:C]
}
}
然后:
grunt.registerTask(prod,[concurrent:prod]);
grunt.registerTask(dev,[concurrent:dev]);
Is it possible to run two watch tasks simultaneously?
I understand that I can have any number of tasks I want inside watch settings and just launch grunt watch and it will watch all of them, like this
...
watch: {
A: {
files: "js/dev/**/*.coffee",
tasks: ["coffee", "requirejs"]
},
B: {
files: "js/dev/**/*.coffee",
tasks: ["coffee"]
},
C: {
files: "js/dev/**/*.html",
tasks: ["copy"]
}
}
...
...but I don't need this. I just want to have different set of tasks for development and production. As you can guess, the only difference between A (production) and B (development) is minification and concatenation. I don't need to launch A and B tasks at the same time.
First I came with this idea
grunt.registerTask("prod", ["watch:A", "watch:C"]);
grunt.registerTask("dev", ["watch:B", "watch:C"]);
But this didn't work. Just first watch tasks is working (C never works). Is that possible to do what I want?
I've found using grunt-concurrent works:
concurrent: {
options: {
logConcurrentOutput: true
},
prod: {
tasks: ["watch:A", "watch:C"]
},
dev: {
tasks: ["watch:B", "watch:C"]
}
}
Then:
grunt.registerTask("prod", ["concurrent:prod"]);
grunt.registerTask("dev", ["concurrent:dev"]);
这篇关于如何同时运行两个grunt监视任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!