Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a common pattern in my gulpfile.js:

var rev         = require('gulp-rev');
var buffer      = require('gulp-buffer');

gulp.src.some_stuff
  .pipe(anotherStuff)
  .pipe(buffer()) // this line & 4 lines down
  .pipe(rev())
  .pipe(gulp.dest(options.dest))
  .pipe(rev.manifest({ path: 'manifest.json', merge: true }))
  .pipe(gulp.dest(options.dest)) // to this
  .pipe(extrastuff)

I want to compose these 5 lines to reuse them in my project over a couple of gulp tasks. How can I do that?

I found multipipe package but it doesn't support passing variables to new pipes (you can see I need to pass options.dest in my new pipe).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
493 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use lazypipe:

var lazypipe = require('lazypipe');

function something(dest) {
  return (lazypipe()
   .pipe(buffer)
   .pipe(rev)
   .pipe(gulp.dest, dest)
   .pipe(rev.manifest, { path: 'manifest.json', merge: true })
   .pipe(gulp.dest, dest))();
}

gulp.src.some_stuff
  .pipe(anotherStuff)
  .pipe(something(options.dest))
  .pipe(extrastuff)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...