0

Is there an option to run a particular task after each watch run? e.g.

watch : {
  js: {files:[], tasks:[]},
  css: {files:[], tasks:[]},
}

I want to run task "foo" after both watch:js and watch:css, and I don't want to add that task to each and every watch multitasks tasks list, and I don't want to add a new watch task with all files from other tasks to be watched.

Is there a watch general options.afterEach api or something?

Greg Venech
  • 8,062
  • 2
  • 19
  • 29
mbehzad
  • 3,758
  • 3
  • 22
  • 29
  • were you able to resolve this? – Greg Venech May 14 '16 at 05:50
  • @SkipJack, thanks for your answer, but i wanted something more clean that could be later maintained and used by other team members. i would probably have to add setTimeout to the event callback to postpone the execution to after other tasks. and i'm no so sure what happens in combination with grunt-concurrent. – mbehzad May 17 '16 at 08:39
  • No problem, yea I actually don't use Grunt anymore (moved to Webpack) but I was surprised that there wasn't a more maintainable option for this as it seems like a somewhat common use case. I think your best bet might be to subscribe to that github issue and see what others are suggesting there. – Greg Venech May 17 '16 at 11:47

1 Answers1

0

Short Answer: No

There isn't a built-in way with Grunt or Grunt Watch. This github issue discusses the possibility of adding in the next version.

There is a watch event but nothing like watch:start or watch:end as far as I know. You can use the this event like so:

grunt.event.on('watch', function(action, filepath, target) {
    grunt.log.writeln('Here is the action : ' + action);
    grunt.log.writeln('Here is the filepath : ' + filepath);
});

Unfortunately this only runs at the beginning:

Running "watch" task
Waiting...
Here is the action : changed
Here is the filepath : pre/js/console.js
>> File "pre/js/console.js" changed.
Running "jshint:all" (jshint) task
...

Related Questions:

Is it possible to run a task after the watch task?

Run a command after a grunt task finishes

Community
  • 1
  • 1
Greg Venech
  • 8,062
  • 2
  • 19
  • 29