简体   繁体   English

gulp.watch不按顺序运行任务

[英]gulp.watch does not run tasks in order

Objective 目的

Create a gulp.watch task to run others tasks in a specific order 创建gulp.watch任务以按特定顺序运行其他任务

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 . 很多人建议我看一下如何依次运行Gulp任务 However, this question focuses on gulp.task while my question focuses on gulp.watch . 但是,这个问题集中在gulp.task而我的问题则集中在gulp.watch

The solution I am searching is a way to use gulp.watch to achieve the synchronous effect I am after. 我正在搜索的解决方案是一种使用gulp.watch来实现我所追求的同步效果的方法。 If this is not possible however, I will fall-back to gulp.task . 如果这不可能,我会回到gulp.task

Background 背景

I have a small project, I have some test files as well as the the gulp gulp-complexity plugin. 我有一个小项目,我有一些测试文件以及gulp gulp-complexity插件。 I wish to run the test files first, and then run the gulp-complexity plugin every time a JavaScript file is changed. 我希望首先运行测试文件,然后每次更改JavaScript文件时运行gulp-complexity插件。

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. 它们非常好,但我仍然不明白我如何能够同步(以特定顺序)运行任务而不是异步运行任务的gulp.watch任务。

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! 请记住,我仍然是一个非常新的gulp(今天开始学习它!)所以对我的问题的任何解释都是受欢迎的!

This is a Gulp issue and should be be fixed in gulp 4.0 这是一个Gulp问题 ,应该在gulp 4.0中修复

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM