You can run tasks in series, by passing a second parameter to gulp.task()
.
This parameters is an array of tasks to be executed and completed before your task will run:
var gulp = require('gulp');
gulp.task('one', function() {
// compile sass css
});
gulp.task('two', function() {
// compile coffeescript
});
// task three will execute only after tasks one and two have been completed
// note that task one and two run in parallel and order is not guaranteed
gulp.task('three', ['one', 'two'], function() {
// concat css and js
});
// task four will execute only after task three is completed
gulp.task('four', ['three'], function() {
// save bundle to dist folder
});
You can also omit the function if you only want to run a bundle of dependency tasks:
gulp.task('build', ['array', 'of', 'task', 'names']);
Note: The tasks will run in parallel (all at once), so don't assume that the tasks will start/finish in order. Starting gulp v4, gulp.series()
should be used if the order of execution of dependency tasks is important.