.pipe调用一个gulp插件时,会发生什么?
例如,这里是一个简单的gulp插件
'use strict'; var match = require('gulp-match'); var ternaryStream = require('ternary-stream'); var through2 = require('through2'); module.exports = function (condition, trueChild, falseChild, minimatchOptions) { if (!trueChild) { throw new Error('gulp-if: child action is required'); } if (typeof condition === 'boolean') { // no need to evaluate the condition for each file // other benefit is it never loads the other stream return condition ? trueChild : (falseChild || through2.obj()); } function classifier (file) { return !!match(file, condition, minimatchOptions); } return ternaryStream(classifier, trueChild, falseChild); };
这是一个典型的用例
gulp.task('task', function() { gulp.src('./src/*.js') .pipe(gulpif(condition, uglify())) .pipe(gulp.dest('./dist/')); });
我正在弄清楚发生了什么事情
根据文档,每一个插件是假设通过一个乙烯基文件,并返回一个乙烯基文件。
但乙烯基文件在哪里传递?
唯一传入的参数是condition, trueChild, falseChild, minimatchOptions
此外,pipe道如何从插件接收返回乙烯基文件?