मैं दो पाइप फ़ंक्शंस लिखने के लिए एक दिन की कोशिश कर रहा हूं, जो कम फ़ाइलों को संकलित करता है और दूसरा जो इन फ़ाइलों को संगत करता है। मैं सीखना चाहता हूं कि अधिक जटिल प्लगइन के लिए ट्रांसफॉर्म स्ट्रीम/पाइप कैसे लिखना है।मैं एक साधारण गल्प पाइप फ़ंक्शन कैसे लिख सकता हूं?
तो मैं जानना चाहता हूं कि किसी अन्य पाइप से डेटा कैसे पढ़ा जाए, और उस डेटा को कैसे बदलें और इसे अगले पाइप पर कैसे भेजें। यह मेरे पास अब तक है:
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