使用PassThrough重复Gulp乙烯基流 - “TypeError:无效的非字符串/缓冲区块”

时间:2015-01-04 04:13:18

标签: node.js stream gulp

在Node中,我正在尝试使用Passthrough复制gulp乙烯基流。我在尝试TypeError: Invalid non-string/buffer chunk

时得到c = fileStream.pipe(b);

我怀疑这可能是因为fileStream是一个含糊的乙烯基流。

var pass = require('stream').PassThrough;

function duplicateStream(fileStream) {
    b = new pass();
    c = fileStream.pipe(b);
    return c;
}

1 个答案:

答案 0 :(得分:3)

如果您需要克隆gulp流,可以使用gulp-clone。此任务将所有单个JS文件写入out目录,以及同一目录中的连接bundle.js

var gulp = require('gulp');
var concat = require('gulp-concat');
var clone = require('gulp-clone');
var merge = require('merge-stream');

gulp.task('default', function () {
    var scripts = gulp.src('assets/**/*.js');

    var bundle = scripts.pipe(clone())
      .pipe(concat('bundle.js'));

    // Merge the streams together, then write them to the out folder
    return merge(scripts, bundle).pipe(gulp.dest('out'));
});

https://github.com/mariocasciaro/gulp-clone