How to run Gulp tasks sequentially one after the other

前端 未结 14 1015
眼角桃花
眼角桃花 2020-11-22 13:00

in the snippet like this:

gulp.task \"coffee\", ->
    gulp.src(\"src/server/**/*.coffee\")
        .pipe(coffee {bare: true}).on(\"error\",gutil.log)
           


        
14条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 13:16

    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.

提交回复
热议问题