Multiple synchronous streams in one Gulp task?

Jake Wilson

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?

Ben

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);
});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Gulp: how to watch multiple files and perform a task for only the changes files?

来自分类Dev

Save and load multiple memory streams in one file C#

来自分类Dev

Gulp.task 意外令牌

来自分类Dev

create/drop database task for gulp/knex

来自分类Dev

通过Gulp Task将变量注入html

来自分类Dev

如何使gulp-replace-task替换html文件中的文本?

来自分类Dev

Visual Studio Task Runner Explorer 无法识别 gulp 任务

来自分类Dev

Android Async Task one after another

来自分类Dev

Multiple Selects into one select

来自分类Dev

使用Intent.FLAG_ACTIVITY_MULTIPLE_TASK

来自分类Dev

Laravel 5 Elixir + gulp mix and version multiple css or less files

来自分类Dev

Clojure, concat multiple sequences into one

来自分类Dev

Join multiple records to one row?

来自分类Dev

How to write multiple statements in one if block in clojure?

来自分类Dev

Left join multiple tables onto one table

来自分类Dev

How to undo strsplit to put multiple characters into one

来自分类Dev

Check multiple checkboxes with one global funtion

来自分类Dev

Multiple Summer note divs on one page

来自分类Dev

Find matching type for one of multiple joined tables

来自分类Dev

sed to replace multiple words but skip one

来自分类Dev

Opposite of tidyr::separate, concatenating multiple columns into one

来自分类Dev

Jquery - Multiple function calls to one AJAX call

来自分类Dev

Aborting synchronous ReadDirectoryChangesW

来自分类Dev

从VS 2015 Task Runner资源管理器运行时,Gulp任务失败,但从命令提示符下运行时失败

来自分类Dev

Create two task in C# .net and close one of them after specific period of time

来自分类Dev

Import multiple excel files into python pandas and concatenate them into one dataframe

来自分类Dev

Multiple UPDATE in single transaction vs one UPDATE with big WHERE clause

来自分类Dev

Neo4j gem - Querying multiple parameters in one property

来自分类Dev

Passing external function of multiple variables as a function of one variable in Fortran

Related 相关文章

  1. 1

    Gulp: how to watch multiple files and perform a task for only the changes files?

  2. 2

    Save and load multiple memory streams in one file C#

  3. 3

    Gulp.task 意外令牌

  4. 4

    create/drop database task for gulp/knex

  5. 5

    通过Gulp Task将变量注入html

  6. 6

    如何使gulp-replace-task替换html文件中的文本?

  7. 7

    Visual Studio Task Runner Explorer 无法识别 gulp 任务

  8. 8

    Android Async Task one after another

  9. 9

    Multiple Selects into one select

  10. 10

    使用Intent.FLAG_ACTIVITY_MULTIPLE_TASK

  11. 11

    Laravel 5 Elixir + gulp mix and version multiple css or less files

  12. 12

    Clojure, concat multiple sequences into one

  13. 13

    Join multiple records to one row?

  14. 14

    How to write multiple statements in one if block in clojure?

  15. 15

    Left join multiple tables onto one table

  16. 16

    How to undo strsplit to put multiple characters into one

  17. 17

    Check multiple checkboxes with one global funtion

  18. 18

    Multiple Summer note divs on one page

  19. 19

    Find matching type for one of multiple joined tables

  20. 20

    sed to replace multiple words but skip one

  21. 21

    Opposite of tidyr::separate, concatenating multiple columns into one

  22. 22

    Jquery - Multiple function calls to one AJAX call

  23. 23

    Aborting synchronous ReadDirectoryChangesW

  24. 24

    从VS 2015 Task Runner资源管理器运行时,Gulp任务失败,但从命令提示符下运行时失败

  25. 25

    Create two task in C# .net and close one of them after specific period of time

  26. 26

    Import multiple excel files into python pandas and concatenate them into one dataframe

  27. 27

    Multiple UPDATE in single transaction vs one UPDATE with big WHERE clause

  28. 28

    Neo4j gem - Querying multiple parameters in one property

  29. 29

    Passing external function of multiple variables as a function of one variable in Fortran

热门标签

归档