Chuck Fecht Chuck Fecht - 3 months ago 6x
Node.js Question

What exactly does .pipe() mean in gulp?

I am relatively new to gulp, and I was wondering what exactly does the

do in a gulp task? I've gathered that it usually runs after a
and after
, but there must be more to it than that. I've been unable to find anything on the web or in gulp's documentation and I really want to understand what I'm using.

I found this, but it does a poor job of explaining it


From the Node docs:

The readable.pipe() method attaches a Writable stream to the readable, causing it to switch automatically into flowing mode and push all of its data to the attached Writable. The flow of data will be automatically managed so that the destination Writable stream is not overwhelmed by a faster Readable stream.

So in Gulp you can chain multiple tasks together using the pipe() method. Gulp makes use of streams. There are readable and writeable streams. Take the following snippet for example:

    .pipe(gulp.dest(config.dest + '/js'))

gulp.src(...) turns the path at config.jsSrc into a readable stream of data that we are then piping to the gulp-uglify module. The uglify task returns a stream that we then pipe to our destination and so on...