如何同时运行两个grunt监视任务 [英] How to run two grunt watch tasks simultaneously

查看:92
本文介绍了如何同时运行两个grunt监视任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以同时运行两个监视任务?



据我所知,我可以在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆