几个Gulp任务等待另一个任务

编程入门 行业动态 更新时间:2024-10-17 16:30:45
本文介绍了几个Gulp任务等待另一个任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要建立的咕嘟咕嘟的任务,像这样的顺序:

任务1 - > Task2A,Task2B,Task2C - >任务3,

其中任务2A,2B,2C并行运行(但task1应该在之前完成,并且只完成一次)。

我尝试过:

gulp.task('Task1',[]); gulp.task('Task2A',['Task1']); gulp.task('Task2B',['Task1']); gulp.task('Task2C',['Task1']); gulp.task('Task3',['Task2A','Task2B','Task2C']);

看起来像是在工作,但我不确定,它是否保证只会执行Task1 1次,或者它可以被触发多次?

谢谢。

解决方案

也许最简单的方法(不使用gulp4.0)是 run-序列插件。

您的情况:

var runSequence = require('run-sequence'); gulp.task('build',function(callback){ runSequence('Task1', ['Task2A','Task2B','Task2C'],'Task3',回调); });

确保您的所有任务都有返回语句。

请注意

这是一个临时解决方案,直到发布gulp 4.0应该支持定义任务

考虑到Gulp 4似乎永远不会完全发布,请将其作为您的愿望。请注意,此解决方案是一种破解方式,可能会在将来更新gulp时停止工作。

I need to build a sequence of Gulp tasks like this:

Task1 -> Task2A, Task2B, Task2C -> Task3,

where tasks 2A,2B,2C run in parallel(but task1 should be completed before, and completed just once).

What I tried:

gulp.task('Task1', []); gulp.task('Task2A', ['Task1']); gulp.task('Task2B', ['Task1']); gulp.task('Task2C', ['Task1']); gulp.task('Task3', ['Task2A', 'Task2B', 'Task2C']);

Looks like it's working, but I'm not sure, does it guarantee that Task1 will be executed only 1 time, or it can be triggered multiple times?

Thank you.

解决方案

Perhaps the simplest way to do this (without using gulp4.0) is the run-sequence plugin.

For your case:

var runSequence = require('run-sequence'); gulp.task('build', function(callback) { runSequence( 'Task1', ['Task2A', 'Task2B', 'Task2C'], 'Task3', callback); });

Make sure you have return statements in all your tasks.

Please Note

This was intended to be a temporary solution until the release of gulp 4.0 which should have support for defining task dependencies similarly.

Given that Gulp 4 appears to never be fully released, take that for what you will. Be aware that this solution is a hack, and may stop working with a future update to gulp.

更多推荐

几个Gulp任务等待另一个任务

本文发布于:2023-11-12 10:40:41,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几个   Gulp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!