4

I have looked all over the documentation and NPM to try to find a solution to this, but I have had no luck. I would like to have the option to skip the tasks that I list as dependencies when running a specific task. For example, if I have the following:

gulp.task('prerun', function(){
  // do cleaning, installation, etc.
});

gulp.task('run', ['prerun'], function(){
  // do stuff
});

gulp.task('watch', function(){
  gulp.watch('glob/glob/**', ['run']);
});

I would like to be able to have my gulp.watch execute run without having to touch the overhead involved in prerun. Is this at all possible in Gulp?

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
nmagerko
  • 6,586
  • 12
  • 46
  • 71

2 Answers2

0

What's about a helper task? I use this approach to eliminate any dependencies in my watch tasks. Your example can look like this:

gulp.task('prerun', function(){
    // do cleaning, installation, etc.
});

gulp.task('run', ['prerun'], function(){
    gulp.start('run-dev');
});

gulp.task('run-dev', function() {
    // do the run stuff
});

gulp.task('watch', function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});

The prerun task you can also use as dependency for your watch task if needed:

gulp.task('watch', ['prerun'], function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});

Ciao Ralf

RWAM
  • 6,760
  • 3
  • 32
  • 45
  • 1
    I was thinking about taking this approach, but from my understanding, it is not particularly good practice to use `gulp.start` (it might get removed in the future). This would make the task a lot easier, though! – nmagerko Aug 20 '14 at 14:53
0

Without using gulp.start, you can try this:

gulp.task('prerun', function(){
    // do cleaning, installation, etc.
});

// run all dependencies while keeping run-dev as a separate task
gulp.task('run', ['prerun', 'run-dev']);

gulp.task('run-dev', function() {
    // do the run stuff
});

gulp.task('watch', ['run'], function(){
    gulp.watch('glob/glob/**', ['run-dev']);
});
Regican
  • 71
  • 1
  • 4