Search code examples
gulprun-sequence

gulp.watch only runs once when passed a run-sequence task


I have a gulpfile, it uses run sequence and gulp.watch().

Here is an example task that uses run sequence.

gulp.task('rebuild', function (callback) {
    runSequence('clean',
                'lint',
                ['process-js', 'process-styles', 'move-fonts', 'move-static-content']);
});

When I make a change to a file, the watch task will run the task I specified exactly once. In this case, the task that should be executed is "run", which is the same as the default task except it doesn't run the dev server and watch task again. Nothing happens when I make further edits, whether in the same file or a different one.

If I pass gulp.watch a plain gulp task (without run sequence), for example the clean task, then the watch will run the clean task every time.

I'm sure I'm doing something wrong, but I don't understand what. I think something might be silently erroring and disconnecting the stream, but I can't figure out how to debug this.


Solution

  • You aren't passing the callback into run-sequence, therefore the task never completes. - OverZealous

    So the run sequence task needs to look like this:

    gulp.task('rebuild', function (callback) {
        runSequence('clean',
                    'lint',
                    ['process-js', 'process-styles', 'move-fonts', 'move-static-content'],
                    callback);
    });