How do I force gulp calls to run synchronously?(如何强制 gulp 调用同步运行?)
问题描述
我希望下面的 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 调用同步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何强制 gulp 调用同步运行?
基础教程推荐
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 动态更新多个选择框 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01