本文介紹了如何為 gulp 組成管道序列?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時(shí)送ChatGPT賬號(hào)..
我的 gulpfile.js
中有一個(gè)通用模式:
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)
我想編寫這 5 行代碼,以便在我的項(xiàng)目中通過幾個(gè) gulp 任務(wù)重用它們.我該怎么做?
I want to compose these 5 lines to reuse them in my project over a couple of gulp tasks. How can I do that?
我找到了 multipipe 包,但它不支持將變量傳遞給新管道(您可以看到我需要在我的新管道中傳遞 options.dest
).
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).
推薦答案
使用 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)
這篇關(guān)于如何為 gulp 組成管道序列?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!