I know that one commonly used method to make a Gulp task synchronous is to return
the output:
gulp.task('mytask', function(){
return gulp.src('myfile.css')
.pipe(dosomething())
.pipe(gulp.dest('./css'));
});
But what do you do if there are multiple streams that occur in a single task?
gulp.task('anothertask', function(){
gulp.src('file1.css')
.pipe(dosomething())
.pipe(gulp.dest('./css'));
gulp.src('file2.css')
.pipe(dosomethingElse())
.pipe(gulp.dest('./css'));
});
How do you go about making this task synchronous? Currently, Gulp reports that the task finishes immediately and the streams are running at the same time and finish after the task is "finished". Obviously this is because no streams are being returned. Should I just return the last stream in the task? Or is it more proper to return the result of both tasks? If so, how do you do that?
The recommended way to use multiple pipelines in a gulp task is by using merge-stream
:
var merge = require('merge-stream');
gulp.task('anothertask', function(){
var stream1 = gulp.src('file1.css')
.pipe(dosomething())
.pipe(gulp.dest('./css'));
var stream2 = gulp.src('file2.css')
.pipe(dosomethingElse())
.pipe(gulp.dest('./css'));
return merge(stream1, stream2);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With