Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
335 views
in Technique[技术] by (71.8m points)

javascript - 如何一个接一个地顺序运行Gulp任务(How to run Gulp tasks sequentially one after the other)

in the snippet like this:

(在这样的代码片段中:)

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"

In develop task I want to run clean and after it's done, run coffee and when that's done, run something else.

(在develop任务中,我希望运行clean并在完成后运行coffee ,当完成后,运行其他东西。)

But I can't figure that out.

(但我无法弄明白。)

This piece doesn't work.

(这件作品不起作用。)

Please advise.

(请指教。)

  ask by iLemming translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

By default, gulp runs tasks simultaneously, unless they have explicit dependencies.

(默认情况下,gulp同时运行任务,除非它们具有显式依赖关系。)

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.

(这对于像clean这样的任务来说并不是很有用,你不想依赖它,但是你需要它们才能在其他任何事情之前运行。)

I wrote the run-sequence plugin specifically to fix this issue with gulp.

(我写了一个run-sequence插件,专门用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.

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

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.

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

However, that is a major breaking change, so there's no reason to wait when you can use run-sequence today.

(但是,这是一个重大的突破性变化,因此没有理由等待今天可以使用run-sequence 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...