4

I'm migrating my build system over to gulp, and have encountered a problem:

I have defined various build tasks (scripts, style, jade, etc), as well as a clean task that removes all of the built files.

I want to make sure that the build tasks don't run before the clean tasks, BUT I also want to be able to run the build tasks without cleaning first.

i.e. I want:

gulp.task('build', ['clean', 'scripts', 'style', 'jade']);

To only start running scripts, style and jade after clean has finished, but

gulp.task('watch', function(){

  gulp.watch('path/to/stylus', ['css']);

});

Should not trigger clean to be run, which would be the case if css had a dependency on clean.

Ed_
  • 18,798
  • 8
  • 45
  • 71
  • I don't know gulp, but I do know the [async](https://github.com/caolan/async) module by caolan. If it's possible to use gulp inside functions with async. You can be helped by [async.auto](https://github.com/caolan/async#auto) which has a natural notation for dependencies of asynchronous jobs to be finished. Do function C only when A and B are done. And do D when C is done. – Christiaan Westerbeek Jun 21 '14 at 13:34
  • In some cases I don't know how to get rid of `gulp.run`, in this case for example. – axelduch Jun 21 '14 at 13:48
  • They removed the run method... – coma Jun 21 '14 at 13:58
  • possible duplicate of [Gulp. can't figure how to run tasks synchronously after each other](http://stackoverflow.com/questions/22824546/gulp-cant-figure-how-to-run-tasks-synchronously-after-each-other) – Evan Davis Jul 30 '14 at 17:44
  • @Mathletics This is NOT a duplicate due to the second part of the question: _"I also want to be able to run the build tasks without cleaning first."_ – Dheeraj Vepakomma Nov 22 '14 at 08:09

1 Answers1

2

I've faced the same problem:

...
var sequence = require('run-sequence');

gulp.task('dev', ['css', 'js', 'html']);

gulp.task('watch', function() {

    gulp.watch(src.css, ['css']);
    gulp.watch(src.js, ['js']);
    gulp.watch(src.html, ['html']);
});

gulp.task('default', function(done) {

    sequence('clean', 'dev', 'watch', done);
});

https://www.npmjs.org/package/run-sequence

Please, read:

This is intended to be a temporary solution until orchestrator is updated to support non-dependent ordered tasks.

BTW, thanks https://stackoverflow.com/users/145185/overzealous!

Community
  • 1
  • 1
coma
  • 16,429
  • 4
  • 51
  • 76