node.js - .pipe() 在 gulp 中到底是什么意思?

标签 node.js gulp

我对 gulp 比较陌生,我想知道 .pipe() 在 gulp 任务中到底做了什么?我收集到它通常在 return.src 之后运行,但肯定不止这些。我在网上或 gulp 的文档中找不到任何东西,我真的很想了解我在使用什么。

编辑 我找到了 this ,但解释起来很糟糕

最佳答案

来自 Node 文档:

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.

因此,在 Gulp 中,您可以使用 pipe() 方法将多个任务链接在一起。 Gulp 使用流。有可读和可写的流。以以下代码段为例:

gulp.src(config.jsSrc)
    .pipe(uglify())
    .pipe(gulp.dest(config.dest + '/js'))
    .pipe(size());

gulp.src(...)config.jsSrc 处的路径转换为可读的数据流,然后我们将其传送到 gulp-丑化 模块。 uglify 任务返回一个流,然后我们将其通过管道传输到我们的目的地,依此类推......

由于流通常是单个文件,有些人可能会混淆 Gulp 如何将多个文件放入流中。 Gulp 实际上在 object mode 中使用流:

gulp.src('*.js') reads all files ending in .js and emits each as an object on the stream.

来源:https://medium.com/gulpjs/gulp-sips-how-we-use-streams-d7790b22bf1a

关于node.js - .pipe() 在 gulp 中到底是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404862/

相关文章:

node.js - 如何通过查询子文档找到Mongoose文档?

javascript - karma 没有执行测试用例

javascript - 如何让 Gulp4 等待文件写入任务竞争?

javascript - Gulp - 管理库依赖项

node.js - 从 Visual Studio 2015 任务运行程序运行 Gulpfile 时出错

javascript - 使用 Package.json 在 $HOME/Sites 文件夹中创建一个文件夹

javascript - gulp 通知依赖于任务完成而无需 .pipe

node.js - 你如何更新 Node.js 中的一对多关系?

javascript - NodeJS Multer 不工作

mysql - 本地主机上的 Node.js 应用程序崩溃