问题
I'm a bit confused about the order in which tasks are completed using Gulp. Allow me to explain.
In gulpfile.js, I have all my required dependencies followed by a set of tasks.
The basic template of each sub task is
gulp.task('compress:customName', function() {
return gulp.src(['app/folder/file.js', 'app/folder/file.js'])
.pipe(gp_concat('app.customName.min.js'))
.pipe(gp_uglify())
.pipe(gulp.dest(distDir));
});
Then, I have a task that rules them all
gulp.task('compress:all', [
'compress:customName1',
'compress:customName2',
'etc...'
], function() {});
Then one more master task runner (just using compress:all for this example)
gulp.task('master', ['compress:all'], function() {
return gulp.src('dist/*.js')
.pipe(notify("COMPRESSION COMPLETE"));
});
OK...that's the basic setup...now to talk about the order in which these tasks appear to be completed per the command line results.
[11:06:44] Using gulpfile C:\PATH\TO\PROJECT\gulpfile.js
[11:06:44] Starting 'compress:customName1'...
[11:06:44] Starting 'compress:customName2'...
[11:06:44] Starting 'compress:customName3'...
[11:06:44] Starting 'compress:customName4'...
[11:06:44] Starting 'compress:customName5'...
[11:06:44] Starting 'compress:customName6'...
[11:06:44] Starting 'compress:customName7'...
[11:06:44] Finished 'compress:customName1' after 108 ms
[11:06:44] Finished 'compress:customName6' after 93 ms
[11:06:44] Finished 'compress:customName5' after 132 ms
[11:06:44] Finished 'compress:customName4' after 139 ms
[11:06:44] Finished 'compress:customName3' after 233 ms
[11:06:44] Finished 'compress:customName2' after 245 ms
[11:06:44] Finished 'compress:customName7' after 381 ms
[11:06:44] Starting 'compress:all'...
[11:06:44] Finished 'compress:all' after 6.64 µs
[11:06:44] Starting 'master'...
[11:06:44] gulp-notify: [SO EXAMPLE : Gulp Builder] COMPRESSION COMPLETE
[11:06:44] Finished 'master' after 40 ms
How can 'master' be the last task to start and starts AFTER 'compress:all'?
Why are the Finished tasks displaying in such a random order?
Why is it that 'master' is said to have completed in only 40 ms when it should be waiting for all the sub-tasks it invokes to respond before considering itself complete?
回答1:
How can 'master' be the last task to start and starts AFTER 'compress:all'?
Dependencies are run before actual task is started. 'compress:all' is dependency for 'master'.
Why are the Finished tasks displaying in such a random order?
Dependencies are run in parallel i.e. when one finishes depends only on the time it takes to complete one.
Why is it that 'master' is said to have completed in only 40 ms when it should be waiting for all the sub-tasks it invokes to respond before considering itself complete?
Dependencies are not included in the completion time of a task.
"deps – An array of tasks to be executed and completed before your task will run."
https://github.com/gulpjs/gulp/blob/master/docs/API.md#deps
来源:https://stackoverflow.com/questions/26741311/in-what-order-does-gulp-process-tasks