There are basically three ways to do this.
1. Definition of dependent tasks
Gulp allows developers to define dependent tasks by passing an array of task names as second arguments:
gulp.task('concat', function () { // ... }); gulp.task('uglify', ['concat'], function () { // ... }); gulp.task('test', ['uglify'], function () { // ... }); // Whenever you pass an array of tasks each of them will run in parallel. // In this case, however, they will run sequentially because they depend on each other gulp.task('build', ['concat', 'uglify', 'test']);
2. Using the execution sequence
You can also use run-sequence to sequentially run an array of tasks:
var runSequence = require('run-sequence'); gulp.task('build', function (cb) { runSequence('concat', 'uglify', 'test', cb); });
3. Using lazypipe
Although Lazypipe is a library for creating reusable pipelines, you can somehow use it to create sequential tasks. For example:
var preBuildPipe = lazypipe().pipe(jshint); var buildPipe = lazypipe().pipe(concat).pipe(uglify); var postBuildPipe = lazypipe().pipe(karma); gulp.task('default', function () { return gulp.src('**/*.js') .pipe(preBuildPipe) .pipe(buildPipe) .pipe(postBuildPipe) .pipe(gulp.dest('dist')); });
Danilo valente
source share