Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Lazy Pipe for Gulp
var combine = require('stream-combiner');
function lazypipe() {
var createPipeline = function(tasks) {
var build = function() {
return combine.apply(null, {
return t.task.apply(null, t.args);
build.pipe = function(task) {
if(!task) {
throw "Invalid call to lazypipe().pipe(): no task specified";
} else if(typeof task !== 'function') {
throw "Invalid call to lazypipe().pipe(): task is not a function";
return createPipeline(tasks.concat({
task: task,
args:, 1)
return build;
return createPipeline([]);
module.exports = lazypipe;
var jsHintTasks = lazypipe()
.pipe(jshint.reporter, 'jshint-stylish');
// this is OK, because lazypipes are immutable now
var jsTasks = jsHintTasks
.pipe(gulp.dest, 'build/js');
var cssTasks = lazypipe()
.pipe(recess, recessConfig)
Copy link

OverZealous commented Jan 19, 2014

Also, you can use a raw function if you need, like this:

var foo = lazypipe().pipe(function() {
        return jshint({globals: { angular: true }});
    .pipe(jshint.reporter, 'jshint-stylish');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment