Duplicate Gulp Vinyl Stream with PassThrough- `TypeError: Invalid non-string/buffer chunk`

Duplicate Gulp Vinyl Stream with PassThrough- `TypeError: Invalid non-string/buffer chunk`

在 Node 中,我正在尝试使用 Passthrough 复制 gulp 乙烯基流。我在尝试 c = fileStream.pipe(b);

时得到 TypeError: Invalid non-string/buffer chunk

我怀疑可能是因为 fileStream 是 gulp 乙烯基流。

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

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

如果您需要克隆 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