In online examples showing usage of gulp, some tasks return the stream and others don't.
For example, without a return:
gulp.task('tsc', function()
{
gulp.src('**/*.ts')
// ...
});
And the same code, with a return:
gulp.task('tsc', function()
{
return gulp.src('**/*.ts')
// ...
});
Is it necessary to return the stream?
If you do not return a stream, then the asynchronous result of each task will not be awaited by its caller, nor any dependent tasks.
For example, when not returning streams:
Note here that the
scripts
task depends upon thetsc
task. It reports thattsc
completes in 13 milliseconds, which is definitely too fast to be reasonably believed. Then thescripts
task appears to start and complete, again in a very small period of time. Finally, the actual operation performed bytsc
commences. Clearly neithertsc
norscripts
waited for the compilation step to complete.When these tasks return their streams, the output looks rather different:
Here the sequence makes sense, and the reported durations meet expectations.