gulp.watch不按顺序运行任务 [英] gulp.watch does not run tasks in order

查看:116
本文介绍了gulp.watch不按顺序运行任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目标



创建 gulp.watch 任务以按特定顺序运行其他任务



为什么这不是重复的



很多人建议我看看如何依次运行Gulp任务。然而,这个问题集中在 gulp.task 上,而我的问题则集中在 gulp.watch 上。

我正在寻找的解决方案是使用 gulp.watch 来实现我之后的同步效果。如果这是不可能的,我会回退到 gulp.task



背景



我有一个小项目,我有一些测试文件以及gulp gulp-complexity 插件。我希望先运行测试文件,然后在每次更改JavaScript文件时运行 gulp-complexity 插件。



b
  • https://github.com/gulpjs/gulp/ blob / master / docs / API.md

  • https://www.smashingmagazine.com/2014/06/building-with-gulp/



  • 它们非常好,但我仍然不明白我如何拥有 gulp.watch 任务,以同步方式(按特定顺序)运行任务以异步方式运行它们。

    代码



    这是我到目前为止:

      var gulp = require(gulp); 
    var mocha = require(gulp-mocha);
    var complexity = require(gulp-complexity);
    $ b gulp.task(test,function(){
    gulp
    .src(./ test.js)
    .pipe(mocha() )
    .on(error,function(){
    this.emit(end);
    });
    });


    gulp.task(complexity,[test],function(){
    gulp.src('*。js')。pipe(complexity() );
    });
    $ b $ gulp.task(watch,function(){
    gulp.watch(./*。js,[test,complexity]);
    });

    我在这里做错了什么?



    请记住,我还是一个非常新鲜的人(今天开始学习!),所以对我的问题的任何解释都会受到欢迎!

    解决方案

    这是一个 Gulp问题,并应在 gulp 4.0 中修复。



    现在,请尝试 run-sequence [ https://www.npmjs.com/package/run-sequence ]


    Objective

    Create a gulp.watch task to run others tasks in a specific order

    Why this is not a duplicate

    Many people have suggested I take a look at How to run Gulp tasks sequentially one after the other. However, this question focuses on gulp.task while my question focuses on gulp.watch.

    The solution I am searching is a way to use gulp.watch to achieve the synchronous effect I am after. If this is not possible however, I will fall-back to gulp.task.

    Background

    I have a small project, I have some test files as well as the the gulp gulp-complexity plugin. I wish to run the test files first, and then run the gulp-complexity plugin every time a JavaScript file is changed.

    What I have tried

    I read the documentation and saw the following tutorials:

    They were very good, but I still don't understand how I can have a gulp.watch task that runs tasks in synchronously (in a specific order) instead of running them asynchronously.

    Code

    This is what I got so far:

    var gulp = require("gulp");
    var mocha = require("gulp-mocha");
    var complexity = require("gulp-complexity");
    
    gulp.task("test", function(){
        gulp
        .src("./test.js")
        .pipe(mocha())
        .on("error", function(){
            this.emit("end");
        });
    });
    
    
    gulp.task("complexity", ["test"], function(){
        gulp.src('*.js').pipe(complexity());
    });
    
    gulp.task("watch", function(){
        gulp.watch("./*.js", ["test", "complexity"]);
    });
    

    What am I doing wrong here?

    Please bare in mind I am still very new to gulp (started learning it today!) so any explanations on my problem would be welcome!

    解决方案

    This is a Gulp issue and should be be fixed in gulp 4.0

    For now, try run-sequence [ https://www.npmjs.com/package/run-sequence ]

    这篇关于gulp.watch不按顺序运行任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆