Reputation: 20616
What is smallest function that can be placed in a Gulp pipe and still work?
This doesn't work:
gulp.src('**')
.pipe(function() {
// what's the minimum that can go here and still be a functional pipe?
// what needs to be returned?
});
Ideally this would be vanilla JS using only the foundational modules Gulp was built on; vinyl, through, etc.
Upvotes: 9
Views: 4914
Reputation: 4090
Yes, it's 4 years later, but I thought I'd throw in my solution to this since I was looking for the same answer.
I wanted some simple, modular pipe
functions that I could reuse in a few different tasks, without excess dependencies. This might not be an elegant solution, but it works:
const gulp = require('gulp');
var someFlag = true;
gulp.task('default', doTask);
function doTask(done) {
let stream = gulp.src(['file.txt'])
.pipe(/* some gulp plugin here */);
if (someFlag) {
stream = alterStream(stream);
}
return stream;
}
function alterStream(stream) {
stream.pipe(/* another gulp plugin here */);
return stream;
}
Instead of returning the stream first directly (return gulp.src(...)
) I'm storing it in a variable, then altering it as needed with other pipes, and returning it last.
Upvotes: 2