Task Dependency in Gulp

感情迁移 提交于 2019-12-12 02:41:43

问题


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'
    ]);

回答1:


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




回答2:


The current gulp task you have at the moment will run correctly, it'll run task-a then run task-b. For whatever reason, it's not giving you back what you want. There's also an npm package called run-sequence (https://www.npmjs.com/package/run-sequence) you can use.

Your gulp task would look something like :

gulp.task('runTasks', function () {
    runSequence('task-a', 'task-b', 'task-c');
});

And that'll execute your tasks in the order sequence you pass it.



来源:https://stackoverflow.com/questions/34285269/task-dependency-in-gulp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!