問題描述
我希望下面的 gulp 調(diào)用一個接一個地同步運(yùn)行.但他們不服從命令.
I want the gulp calls below to run synchronously, one after the other. But they do not follow an order.
run-sequence 節(jié)點(diǎn)模塊在這里沒有幫助,因為我不想運(yùn)行 gulp串聯(lián)任務(wù)(即,它的語法類似于 gulp.task("mytask", ["foo", "bar", "baz"]
等),而是串聯(lián) gulp 調(diào)用",如下所示.
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();
});
如何讓它們一個接一個地運(yùn)行?
How do I make them run one after the other?
推薦答案
你可以使用async 作為您的呼叫的控制流程,讓他們只完成一項任務(wù),同時避免您獲得金字塔效應(yīng)".所以這樣的事情應(yīng)該對你的用例有好處:
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);
});
這也將允許您進(jìn)行一些錯誤處理并更好地定位發(fā)生問題的位置.
That will also allow you to have some error handling and target better where a problem occured.
這篇關(guān)于如何強(qiáng)制 gulp 調(diào)用同步運(yùn)行?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!