我的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行代码,以便在我的项目中通过几个任务重用它们。我怎么能这么做?
我找到了多管包,但它不支持将变量传递给新管道(您可以看到,我需要在新管道中传递options.dest )。
发布于 2016-04-02 12:21:30
使用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)https://stackoverflow.com/questions/36371628
复制相似问题