How to run Gulp tasks sequentially one after the other?

Published on Author Code Father
How to run Gulp tasks sequentially one after the other?

By default, gulp runs tasks simultaneously, unless they have explicit dependencies. This isn’t very useful for tasks like clean, where you don’t want to depend, but you need them to run before everything else. I wrote the run-sequence plugin specifically to fix this issue with gulp. After you install it, use it like this:

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

gulp.task('develop', function(done) {
    runSequence('clean', 'coffee', function() {
        console.log('Run something else');
        done();
    });
});

You can read the full instructions on the package README — it also supports running some sets of tasks simultaneously. Please note, this will be (effectively) fixed in the next major release of gulp, as they are completely eliminating the automatic dependency ordering, and providing tools similar to run-sequence to allow you to manually specify run order how you want. However, that is a major breaking change, so there’s no reason to wait when you can use run-sequence today.

Comments

comments