如何为gulp组成管道顺序?

我有一个共同的模式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)

我想组成这5行,以便在几个吞咽的任务中重复使用它们在我的项目中。我怎样才能做到这一点?

我找到了multipipe包,但是它不支持将变量传递到新管道(您可以看到我需要传递options.dest新管道)。

回答:

用途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)

以上是 如何为gulp组成管道顺序? 的全部内容, 来源链接: utcz.com/qa/407495.html

回到顶部