node.js .pipe() 在 gulp 中到底是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38404862/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What exactly does .pipe() mean in gulp?
提问by Arlo
I am relatively new to gulp, and I was wondering what exactly does the .pipe()do in a gulp task? I've gathered that it usually runs after a returnand after .src, 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.
我对 gulp 比较陌生,我想知道.pipe()gulp 任务到底做了什么?我发现它通常在 areturn和 after 之后运行.src,但肯定不止于此。我一直无法在网络上或 gulp 的文档中找到任何内容,我真的很想了解我在使用什么。
EDIT I found this, but it does a poor job of explaining it
编辑我发现了这个,但它在解释它方面做得很差
采纳答案by pizzarob
From the Node docs:
从节点文档:
https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
https://nodejs.org/api/stream.html#stream_readable_pipe_destination_options
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.
readable.pipe() 方法将 Writable 流附加到可读流,使其自动切换到流动模式并将其所有数据推送到附加的 Writable。数据流将被自动管理,以便目标 Writable 流不会被更快的 Readable 流淹没。
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:
因此,在 Gulp 中,您可以使用该pipe()方法将多个任务链接在一起。Gulp 使用流。有可读流和可写流。以下面的代码片段为例:
gulp.src(config.jsSrc)
.pipe(uglify())
.pipe(gulp.dest(config.dest + '/js'))
.pipe(size());
gulp.src(...)turns the path at config.jsSrcinto a readable stream of data that we are then piping to the gulp-uglifymodule. The uglify task returns a stream that we then pipe to our destination and so on...
gulp.src(...)将路径 atconfig.jsSrc转换为可读的数据流,然后我们将其通过管道传输到gulp-uglify模块。uglify 任务返回一个流,然后我们将其通过管道传输到目的地,依此类推……

