我正在写我自己的插件,看起来像这样.
var through2 = require('through2');
var order = require('gulp-order');
module.exports = function() {
return through2.obj(function(file, encoding, callback) {
callback(null, transform(file));
});
};
function transform(file) {
// I will modify file.contents here - its ok
return file;
}我想在我的缓冲区上应用一些其他的gulp插件,它来自gulp.src。可以使用through2吗?例如,在调用trans2.obj()之前,我想应用一饮而尽的插件--我如何做到这一点?
发布于 2016-10-13 07:56:52
如果你想把不同的插件链接在一起,lazypipe通常是个不错的选择:
var through2 = require('through2');
var order = require('gulp-order');
function yourPlugin()
return through2.obj(function(file, encoding, callback) {
callback(null, transform(file));
});
}
function transform(file) {
// I will modify file.contents here - its ok
return file;
}
function orderPlugin()
return order(['someFolder/*.js', 'someOtherFolder/*.js']);
}
module.exports = function() {
return lazypipe().pipe(orderPlugin).pipe(yourPlugin)();
};https://stackoverflow.com/questions/40014495
复制相似问题