例如,这是一个简单的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/'));
});
我想知道发生了什么
根据文档,每个gulp插件都假设传入乙烯基文件并返回一个乙烯基文件。
但传递的黑胶唱片文件在哪里?
唯一传入的参数是condition, trueChild, falseChild, minimatchOptions
此外,管道如何从插件接收返回的乙烯基文件?