Last active
August 29, 2015 14:03
-
-
Save blackbing/1c2c96d941e9cad5e29e to your computer and use it in GitHub Desktop.
gulp task async and dependency demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp = require("gulp") | |
$ = require("gulp-load-plugins")() | |
gulp.task 'task1', (callback)-> | |
setTimeout( -> | |
$.util.log( 'task1 done') | |
callback() #notice you need to send callback for chaining | |
, 1500) | |
gulp.task 'task2', (callback)-> | |
setTimeout( -> | |
$.util.log( 'task2 done') | |
callback() #notice you need to send callback for chaining | |
, 1000) | |
gulp.task 'task3', -> | |
gulp.src('app/**/*') | |
.pipe( gulp.dest('dist')) | |
#it will fire task1/2/3 at the same time | |
gulp.task 'build', [ | |
'task1' | |
'task2' | |
'task3' | |
], -> | |
$.util.log 'build done' | |
gulp.task 'build2', -> | |
gulp.start(['task1'],[ 'task2'], ['task3']) | |
# I want make task1 -> task2 -> task3 | |
gulp.task 'o-task1', (callback)-> | |
setTimeout( -> | |
$.util.log( 'o-task1 done') | |
callback() #notice you need to send callback for chaining | |
, 1500) | |
gulp.task 'o-task2', [ | |
'o-task1' | |
], (callback)-> | |
setTimeout( -> | |
$.util.log( 'o-task2 done') | |
callback() #notice you need to send callback for chaining | |
, 1000) | |
gulp.task 'o-task3', ['o-task2'], -> | |
gulp.src('app/**/*') | |
.pipe( gulp.dest('dist')) | |
#it will fire task1/2/3 by ordered | |
gulp.task 'o-build', [ | |
'o-task1' | |
'o-task2' | |
'o-task3' | |
], -> | |
$.util.log 'o-build done' | |
gulp.task 'task2-1', (callback)-> | |
setTimeout( -> | |
$.util.log( 'task2-1 done') | |
callback() #notice you need to send callback for chaining | |
, 1200) | |
gulp.task 'task2-2', (callback)-> | |
setTimeout( -> | |
$.util.log( 'task2-2 done') | |
callback() #notice you need to send callback for chaining | |
, 1200) | |
# use run-sequence(https://github.com/OverZealous/run-sequence) | |
gulp.task 'sequence-build', (callback)-> | |
runSequence = require('run-sequence') | |
runSequence( | |
'task1' | |
'task2' | |
['task2-1', 'task2-2'] | |
'task3' | |
, -> | |
$.util.log 'sequence-build done' | |
callback() | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('coffee-script/register') | |
require('./gulpfile.coffee') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "gulp-test", | |
"version": "0.0.0", | |
"description": "", | |
"main": "gulpfile.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"devDependencies": { | |
"coffee-script": "^1.7.1", | |
"gulp-util": "^2.2.19", | |
"gulp-load-plugins": "^0.5.3", | |
"gulp": "^3.8.5", | |
"run-sequence": "^0.3.6" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment