Gulp中的任务依赖 [英] Task Dependency in Gulp
问题描述
因此,当我运行 build $>时,需要连续执行其他两个任务。当
task-a 时,首先运行
task-a
code>完成
任务-b
执行。
目前我使用这个脚本,我想确认是正确的。
gulp.task('build',[
'task-a',
'task-b'
]);
将平行运行(全部在一次),所以不要认为任务会按顺序开始/结束。
您必须明确定义任务的顺序如下所示,让Gulp锻炼出正确的顺序:
gulp.task('task-a',function(){.. 。});
gulp.task('task-b',['task-a'],function(){...});
gulp.task('build',['task-a','task-b'],function(){...});
此时您将尝试运行 build
Gulp将构建任务和锻炼的依赖关系树,该任务和锻炼 task-a
在执行前完成。
更完整的例子可以在这里找到: https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md
I have a task in gulp that need to execute other two tasks consecutively and in order.
So when I run build
, build
run first task-a
, when task-a
is completed
task-b
is performed.
At the moment I am using this script, I would like to have confirmation the is correct.
gulp.task('build', [
'task-a',
'task-b'
]);
As stated at the official documentation with that format the tasks will run in parallel (all at once), so don't assume that the tasks will start/finish in order.
You have to explicitly define the order of tasks as follow to make Gulp workout the right order:
gulp.task('task-a', function(){ ... });
gulp.task('task-b', ['task-a'], function(){ ... });
gulp.task('build', ['task-a', 'task-b'], function(){ ... });
At this point when you'll try to run build
Gulp will build the dependency tree of the tasks and workout that task-b
relies on task-a
to be completed before executing.
A more complete example can be found here: https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md
这篇关于Gulp中的任务依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!