在这样的片段中:

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

gulp.task "clean",->
    gulp.src("bin", {read:false})
        .pipe clean
            force:true

gulp.task 'develop',['clean','coffee'], ->
    console.log "run something else"

在开发任务中,我想要干净地运行,在它完成后,运行咖啡,当它完成时,运行其他东西。但是我想不出来。这个零件坏了。请建议。


当前回答

The very simple and efficient solution that I found out to perform tasks one after the other(when one task gets completed then second task will be initiated) (providing just an example) is : gulp.task('watch', () => gulp.watch(['src/**/*.css', 'src/**/*.pcss'], gulp.series('build',['copy'])) ); This means when you need to run the first-task before second-task, you need to write the second task(copy in this case) in square brackets. NOTE There should be round parenthesis externally for the tasks(until you want them to occur simultaneously)

其他回答

The very simple and efficient solution that I found out to perform tasks one after the other(when one task gets completed then second task will be initiated) (providing just an example) is : gulp.task('watch', () => gulp.watch(['src/**/*.css', 'src/**/*.pcss'], gulp.series('build',['copy'])) ); This means when you need to run the first-task before second-task, you need to write the second task(copy in this case) in square brackets. NOTE There should be round parenthesis externally for the tasks(until you want them to occur simultaneously)

我一直在寻找这个答案。现在我在gulp的官方文档里找到了。

如果你想在最后一个任务完成时执行gulp任务,你必须返回一个流:

饮而尽。任务('wiredep', ['dev-jade'],函数(){ Var stream = gulp.src(路径。输出+ '*.html') .pipe ($ .wiredep ()) .pipe (gulp.dest (paths.output)); 返回流;//当此任务完成时执行下一个任务 }); //首先执行并完成wiredep任务 饮而尽。任务('prod-jade', ['wiredep'],函数(){ gulp.src(路径。输出+ '**/*.html') .pipe ($ .minifyHtml ()) .pipe (gulp.dest (paths.output)); });

等着看任务是否完成,然后剩下的,我是这样做的:

gulp.task('default',
  gulp.series('set_env', gulp.parallel('build_scss', 'minify_js', 'minify_ts', 'minify_html', 'browser_sync_func', 'watch'),
    function () {
    }));

荣誉:https://fettblog.eu/gulp-4-parallel-and-series/

我也遇到过同样的问题,而且解决方法对我来说非常简单。基本上把你的代码改成下面的代码,它应该可以工作。注意:在吞咽前返回。SRC让我完全不同。

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

gulp.task "clean",->
    return gulp.src("bin", {read:false})
        .pipe clean
            force:true

gulp.task 'develop',['clean','coffee'], ->
    console.log "run something else"

默认情况下,gulp同时运行任务,除非它们有显式的依赖关系。这对于像clean这样的任务不是很有用,在这些任务中,您不希望依赖它们,但您需要在所有其他任务之前运行它们。

我专门用gulp编写了run-sequence插件来解决这个问题。安装后,像这样使用它:

var runSequence = require('run-sequence');

gulp.task('develop', function(done) {
    runSequence('clean', 'coffee', function() {
        console.log('Run something else');
        done();
    });
});

您可以在README包上阅读完整的说明-它还支持同时运行一些任务集。

请注意,这将在gulp的下一个主要版本中(有效地)修复,因为他们完全消除了自动依赖顺序,并提供类似于run-sequence的工具,允许您手动指定您想要的运行顺序。

然而,这是一个重大的突破性变化,所以当您现在可以使用run-sequence时,没有理由等待。