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?
Just change the port address and the livereload port. For eg. if the port is 9000 change it to 8000 and live reload from 35729 to 36729
EDIT: concurrent now has a
logConcurrentOutput
option! More info here: https://github.com/sindresorhus/grunt-concurrent#logconcurrentoutput.Watch is a weirdly concurrent but blocking task, so you have to be creative to get multitask-like functionality working.
Concurrent loses all output from the watch tasks, which isn't ideal.
Try dynamically writing the config object in a custom task:
grunt-concurrent or grunt-focus are both good solutions, but both of them break
livereload
functionality.My solution to this is to compose the watch configuration dynamically, with the assumption that you won't be running both configuration at the same time.
You can do something like this
I know this not answer directly to the question, but my solution is now to use Gulp instead of Grunt. With Gulp you code and not only configure. So you are more free to do what you want.
JM.
The best and only working solution is there : https://npmjs.org/package/grunt-focus Add this plugin and then :
Then you use focus:sources or focus:testu as your convenience.
JM.
SEPTEMBER 2018
You don't need to use grunt-concurrent anymore grunt now has this built in, here is a sample from one of my current projects...