This is how one writes a no-op for .pipe():
const { PassThrough } = require("stream");
function noop() {
return new PassThrough({ objectMode: true });
}
This is how we use it:
Object.entries(bundles).map(([output, inputs]) =>
gulp.src(inputs, { cwd: "./public/js" })
.pipe(concat(output))
.pipe(releaseBuild ? uglify() : noop())
.pipe(gulp.dest("public/js"))
);
Or, if you prefer less syntax sugar, you could always do this:
Object.entries(bundles).map(([output, inputs]) => {
let pipeline = gulp.src(inputs, { cwd: "./public/js" })
.pipe(concat(output));
if (releaseBuild) {
pipeline = pipeline.pipe(uglify());
}
return pipeline.pipe(gulp.dest("public/js"));
});
Before today we were using gulp-if because that's what the web will advise you to do if you search on the topic. It was rather heavy for our use case. Switching to this method took ten packages out of our node_modules directory. I figured somebody ought to publish new advice for future web searchers.
2025-12-22
↑ Home