我一直在嘗試寫一天編寫兩個管道功能,一個編譯較少的文件,另一個連接這些文件。我想學習如何爲更復雜的插件編寫轉換流/管道。如何編寫簡單的吞嚥管功能?
因此,我想知道如何從另一個管道讀取數據,以及如何更改該數據並將其發送到下一個管道。這是我到目前爲止:
gulp.src(sources)
.pipe(through.obj(function (chunk, enc, cb) {
var t = this;
// console.log("chunk", chunk.path);
fs.readFile(chunk.path, enc, function (err,data) {
if (err) { cb(err); }
less.render(data, {
filename : chunk.path,
sourceMap : {
sourceMapRootpath : true
}
})
.then(function (outputCss) {
// console.log("less result",outputCss);
t.push(chunk);// or this.push(outputCss) same result
cb();
});
});
}))
.pipe(through.obj(function (chunk, enc, cb) {
console.log("chunk", chunk.path); // not event getting called.
cb();
}))
我無法獲得第二個管道中的每個文件的outputCSS。我怎樣才能發送它?
https://github.com/gulpjs/gulp/blob/master/docs/writing-a-plugin/dealing-with-streams.md可能會幫助一些人。 – Shanimal