問題描述
我希望下面的 gulp 調用一個接一個地同步運行.但他們不服從命令.
I want the gulp calls below to run synchronously, one after the other. But they do not follow an order.
run-sequence 節點模塊在這里沒有幫助,因為我不想運行 gulp串聯任務(即,它的語法類似于 gulp.task("mytask", ["foo", "bar", "baz"]
等),而是串聯 gulp 調用",如下所示.
The run-sequence node module doesn't help here, as I'm not trying to run gulp tasks in series (i.e. it has syntax similar to gulp.task("mytask", ["foo", "bar", "baz"]
etc.), but rather gulp "calls" in series, as you see below.
gulp.task("dostuff", function (callback) {
gulp
.src("...")
.pipe(gulp.dest("...");
gulp
.src("...")
.pipe(gulp.dest("...");
gulp
.src("...")
.pipe(gulp.dest("...");
callback();
});
如何讓它們一個接一個地運行?
How do I make them run one after the other?
推薦答案
你可以使用async 作為您的呼叫的控制流程,讓他們只完成一項任務,同時避免您獲得金字塔效應".所以這樣的事情應該對你的用例有好處:
You can use async as a control flow for your calls to get them in only one task, also avoiding you to get a "pyramid effect". So something like this should be good for your use-case:
var async = require('async');
gulp.task('yeah', function (cb) {
async.series([
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
},
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
},
function (next) {
gulp.src('...')
.pipe(gulp.dest('...')
.on('end', next);
}
], cb);
});
這也將允許您進行一些錯誤處理并更好地定位發生問題的位置.
That will also allow you to have some error handling and target better where a problem occured.
這篇關于如何強制 gulp 調用同步運行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!