How to break a stream in gulp

Basically, I have a set of files that I process using markdowns and what not. After doing this initial processing, I would like to split the stream into two:

  • Display 1..1 first with additional processing, such as layout
  • Secondly, matching all files in one, for example, an index, without applying the layouts mentioned above.

Is it possible to save the stream in a variable and just save the pipeline? Here is my current task:

gulp.task('default', function() {
    var entries = gulp.src('./log/*.md')
        .pipe(frontMatter())
        .pipe(markdown());

    var templated = entries
        .pipe(applyTemplate())
        .pipe(gulp.dest('./build/log'));

    var index = entries
        .pipe(index())
        .pipe(applyIndexTemplate())
        .pipe(gulp.dest('./build'));

    return merge(templated, index);
}

I could use lazypipe and / or just construct the channel several times, but is there any other way?

+4
source share
2 answers

Node.js docs " ", :

var entries = gulp.src('./log/*.md')
    .pipe(frontMatter())
    .pipe(markdown());

var templated = entries
    .pipe(applyTemplate())
    .pipe(gulp.dest('./build/log'));

var index = entries
    .pipe(index())
    .pipe(applyIndexTemplate())
    .pipe(gulp.dest('./build'));

return merge(templated, index);
+7
var gulpClone = require("gulp-clone");
var eventStream = require('event-stream');

var entries = gulp.src('./log/*.md')
    .pipe(frontMatter())
    .pipe(markdown());

var templated = entries
    .pipe(gulpClone())
    .pipe(applyTemplate())
    .pipe(gulp.dest('./build/log'));

var index = entries
    .pipe(gulpClone())
    .pipe(index())
    .pipe(applyIndexTemplate())
    .pipe(gulp.dest('./build'));

return eventStream.merge(templated, index);
0

All Articles