Closed radekn closed 9 years ago
@radekn You must create two separate streams for the same glob, otherwise the same File
instance will be used. I'm not aware of any gulp plugin that will clone the input file. Does any plugin do that?
var scripts = gulp.src(['src/scripts.js']);
var minified = gulp.src(['src/scripts.js']).pipe(minify())
.pipe(rename({
suffix: '.min'
}));
@crissdev I don't know if any gulp plugin actually handles it that way. To me it seems like a waste because it limits the flexibility of streams API, so I asked a question about this in gulpjs/gulp#754. So far it seems that the official stance is that the current behavior is acceptable. Personally I don't agree, but if it's fine for everyone else, so be it.
As @crissdev said, and already concluded in https://github.com/gulpjs/gulp/issues/754 and https://github.com/terinjokes/gulp-uglify/issues/62.
gulp-rename seems to mutate its input, which means means that changes propagate backwards in the stream pipeline. Consider following code:
mergeStreams
is a function that pipes the sources into one destination stream and closes it when all sources end, andminify
just returns a stream that minifies JS files.This pipeline should write two files:
build/script.js
- an unchanged copy of source file, andbuild/script.min.js
- a processed source file. But instead, it tries to write both files asbuild/script.min.js
.gulp-rename did not just output its input file with changed name, it changed the name of the input file itself. If gulp-rename made a shallow copy of the input file and didn't mutate the input file itself, this problem wouldn't have occurred.