Search code examples
node.jsgulp

Gulp pipe minimal function?


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.


Solution

  • The problem with your pipe is that you're dropping the files of your glob since you don't return them.

    Using through2, you can do something like this:

    const through = require('through2')
    
    gulp.src('**')
      .pipe(through.obj((file, enc, cb) => cb(null, file)))