How to run Gulp tasks sequentially one after the other

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

    For me it was not running the minify task after concatenation as it expects concatenated input and it was not generated some times.

    I tried adding to a default task in execution order and it didn't worked. It worked after adding just a return for each tasks and getting the minification inside gulp.start() like below.

    /**
    * Concatenate JavaScripts
    */
    gulp.task('concat-js', function(){
        return gulp.src([
            'js/jquery.js',
            'js/jquery-ui.js',
            'js/bootstrap.js',
            'js/jquery.onepage-scroll.js',
            'js/script.js'])
        .pipe(maps.init())
        .pipe(concat('ux.js'))
        .pipe(maps.write('./'))
        .pipe(gulp.dest('dist/js'));
    });
    
    /**
    * Minify JavaScript
    */
    gulp.task('minify-js', function(){
        return gulp.src('dist/js/ux.js')
        .pipe(uglify())
        .pipe(rename('ux.min.js'))
        .pipe(gulp.dest('dist/js'));
    });
    
    gulp.task('concat', ['concat-js'], function(){
       gulp.start('minify-js');
    });
    
    gulp.task('default',['concat']); 
    

    Source http://schickling.me/synchronous-tasks-gulp/

提交回复
热议问题