If you are hiring developers, you can support this project and future open source work by checking out our company, Qualified.io .
Qualified is a service for online skills-assessment that can help you easily vet developers across a wide range of real-world programming skills.
Please help support this project, and sign up for a free trial .
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.
npm install --save-dev run-sequence
var gulp = require ( 'gulp' ) ;
var runSequence = require ( 'run-sequence' ) ;
var del = require ( 'del' ) ;
var fs = require ( 'fs' ) ;
// This will run in this order:
// * build-clean
// * build-scripts and build-styles in parallel
// * build-html
// * Finally call the callback function
gulp . task ( 'build' , function ( callback ) {
runSequence ( 'build-clean' ,
[ 'build-scripts' , 'build-styles' ] ,
'build-html' ,
callback ) ;
} ) ;
// configure build-clean, build-scripts, build-styles, build-html as you wish,
// but make sure they either return a stream or promise, or handle the callback
// Example:
gulp . task ( 'build-clean' , function ( ) {
// Return the Promise from del()
return del ( [ BUILD_DIRECTORY ] ) ;
// ^^^^^^
// This is the key here, to make sure asynchronous tasks are done!
} ) ;
gulp . task ( 'build-scripts' , function ( ) {
// Return the stream from gulp
return gulp . src ( SCRIPTS_SRC ) . pipe ( ... ) ... // ^^^^^^
// This is the key here, to make sure tasks run to completion!
} ) ;
gulp . task ( 'callback-example' , function ( callback ) {
// Use the callback in the async function
fs . readFile ( '...' , function ( err , file ) {
console . log ( file ) ;
callback ( ) ;
// ^^^^^^^^^^
// This is what lets gulp know this task is complete!
} ) ;
} ) ;
// submodule tasks/mygulptask.js
var gulp = require ( 'gulp' ) , // might be a different instance than the toplevel one
// this uses the gulp you provide
runSequence = require ( 'run-sequence' ) . use ( gulp ) ;
// ... and then use normally
runSequence ( 'subtask1' , 'subtask2' ) ;
var runSequence = require ( 'run-sequence' ) ;
runSequence . options . ignoreUndefinedTasks = true ;
gulp . task ( 'task' , function ( cb ) {
runSequence ( 'foo' , null , 'bar' ) ; // no longer errors on `null`
} )
showErrorStackTrace : When set to false , this suppresses the full stack trace from errors captured during a sequence. ignoreUndefinedTasks : When set to true , this enables you to pass falsey values in which will be stripped from the task set before validation and sequencing.