如何强制 gulp 调用同步运行?

How do I force gulp calls to run synchronously?(如何强制 gulp 调用同步运行?)
本文介绍了如何强制 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 调用同步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)