在gulp中的es.merge用法:Object#<Stream>没有方法'end'

我正在努力获得两条并行的处理路线。 我的代码如下所示:

gulp.task('build', function(){ return gulp.src(src,{cwd:srcDir}) .pipe(concat('sdk.js', {newLine:'\n\n'})) .pipe(gulp.dest('dist/')) .pipe(jshint()) .pipe(jshint.reporter('default')) .pipe(es.merge( gulp.src('dist/sdk.js') .pipe(preprocess({context:{debug:true}})) .pipe(rename('sdk.debug.js')), gulp.src('dist/sdk.js') .pipe(preprocess({context:{}})) .pipe(uglify()) .pipe(rename('sdk.min.js')) )) //some more processing .pipe(gulp.dest('dist/')) ; }); 

我在这里find了一个build议,这样分叉和合并stream的方式应该是可行的。 但是,我得到的错误:

 stream.js:79 dest.end(); ^ TypeError: Object #<Stream> has no method 'end' at Stream.onend (stream.js:79:10) at Stream.EventEmitter.emit (events.js:117:20) at end (C:\Users\user\Documents\proj\node-sdk\node_modules\gulp- jshint\node_modules\map-stream\index.js:116:39) at Stream.stream.end (C:\Users\user\Documents\proj\node-sdk\node _modules\gulp-jshint\node_modules\map-stream\index.js:122:5) at Stream.onend (stream.js:79:10) at Stream.EventEmitter.emit (events.js:117:20) at end (C:\Users\user\Documents\proj\node-sdk\node_modules\gulp- jshint\node_modules\map-stream\index.js:116:39) at queueData (C:\Users\user\Documents\proj\node-sdk\node_modules \gulp-jshint\node_modules\map-stream\index.js:62:17) at next (C:\Users\user\Documents\proj\node-sdk\node_modules\gulp -jshint\node_modules\map-stream\index.js:71:7) at C:\Users\user\Documents\proj\node-sdk\node_modules\gulp-jshin t\node_modules\map-stream\index.js:85:7 

似乎问题在于es.merge的使用,因为没有它(一个处理path),一切都按预期工作。 不幸的是,我没有广泛的node.jsstream知识,所以我不能确定这个问题的原因。 我的Node版本是0.10.28,吞吐量是3.6.2,事件stream是3.1.5

es.merge不能用作pipe道的目标,因为它不是一个合适的WriteStream。 它实现了write()而不是end()所以它可以沿着传入的stream数据进行转发,但是当上游源完成时, es.merge不处理end事件。 我不知道这是否是es.merge的预期行为,但至less在目前的实施中,它只能作为一个来源。

https://github.com/dominictarr/event-stream/blob/master/index.js#L32

另一个解决scheme是将你的任务分成两个独立的任务,并使用吞吐依赖:

 gulp.task('build-concat', function() { return gulp.src(src,{cwd:srcDir}) .pipe(concat('sdk.js', {newLine:'\n\n'})) .pipe(gulp.dest('dist/')) .pipe(jshint()) .pipe(jshint.reporter('default')); }); gulp.task('build', ['build-concat'], function() { return es.merge( gulp.src('dist/sdk.js') .pipe(preprocess({context:{debug:true}})) .pipe(rename('sdk.debug.js')), gulp.src('dist/sdk.js') .pipe(preprocess({context:{}})) .pipe(uglify()) .pipe(rename('sdk.min.js')) )) //some more processing .pipe(gulp.dest('dist/')) ; });