gulpmanifestgulp-rev

Gulp tasks does not work sequentially


I have 4 tasks to clean the build, build styles & javascripts and to create asset manifest. My default task looks like this:

gulp.task('default', function(callback) {
    runSequence('clean', ['styles', 'scripts'], 'version', callback);
});

So, this works out perfectly but the 'version' tasks. It does not create anything and has no effect.

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

    gulp.src(utils.dst('**/*'))

        // create content hashed filenames
        .pipe(rev())
        .pipe(gulp.dest(utils.dst()))

        // create asset manifest
        .pipe(rev.manifest())
        .pipe(gulp.dest(utils.dst()))

});

If I run do the gulp clean; gulp styles; gulp scripts; gulp version; the version tasks will create the desired asset manifest.

This is the output of running the default task:

Starting 'default'...
Starting 'clean'...
Finished 'clean' after 6.87 ms
Starting 'styles'...
Finished 'styles' after 7.63 ms
Starting 'scripts'...
Finished 'scripts' after 2.96 ms
Starting 'version'...
Finished 'version' after 2.25 ms
Finished 'default' after 22 ms

Do anyone see the mistake I do? Maybe the build assets are not there yet when I run the version task, but that's why I made the tasks run sequentially.

Any suggestions how I could solve the problem?


Solution

  • You have to return the stream like so :

    gulp.task('version', function() {
    
        return gulp.src(utils.dst('**/*'))
    
            // create content hashed filenames
            .pipe(rev())
            .pipe(gulp.dest(utils.dst()))
    
            // create asset manifest
            .pipe(rev.manifest())
            .pipe(gulp.dest(utils.dst()))
    
    });
    

    Otherwise gulp can't know if your task is finished or not !