How to run Gulp tasks sequentially one after the other

前端 未结 14 1018
眼角桃花
眼角桃花 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:13

    According to the Gulp docs:

    Are your tasks running before the dependencies are complete? Make sure your dependency tasks are correctly using the async run hints: take in a callback or return a promise or event stream.

    To run your sequence of tasks synchronously:

    1. Return the event stream (e.g. gulp.src) to gulp.task to inform the task of when the stream ends.
    2. Declare task dependencies in the second argument of gulp.task.

    See the revised code:

    gulp.task "coffee", ->
        return gulp.src("src/server/**/*.coffee")
            .pipe(coffee {bare: true}).on("error",gutil.log)
            .pipe(gulp.dest "bin")
    
    gulp.task "clean", ['coffee'], ->
          return gulp.src("bin", {read:false})
            .pipe clean
                force:true
    
    gulp.task 'develop',['clean','coffee'], ->
        console.log "run something else"
    

提交回复
热议问题