如何强制 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 调用同步运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)