what are the reasons to clone files?
I don't get the first example..why would you do such a thing?
The purpose of gulp-clone is mainly performance and convenience. You could almost always replicate its functionality by re-reading and reprocessing the same source files, or executing some intermediate save.
Look at this discussion for a real-life example: https://github.com/ben-eb/gulp-rsvg/pull/2
I report the code here for convenience:
var svg = gulp
.src('images/svg/*.svg');
var png32 = svg
.pipe(clone())
.pipe(rsvg({ width: 32, height: 32 }))
.pipe(gulp.dest('images/png-32'));
var png64 = svg
.pipe(clone())
.pipe(rsvg({ width: 64, height: 64 }))
.pipe(gulp.dest('images/png-64'));
return es.merge(png32, png64);
The following code would be equivalent to the code above, but as you can see you need to read the files twice (with a small performance impact, and conceptually it feels like repeating the same operation twice):
var png32 = gulp.src('images/svg/*.svg')
.pipe(rsvg({
width: 32,
height: 32
}))
.pipe(gulp.dest('images/png-32'));
var png64 = gulp.src('images/svg/*.svg')
.pipe(rsvg({
width: 64,
height: 64
}))
.pipe(gulp.dest('images/png-64'));
return es.merge(png32, png64);
I understand that the example in the README is not exactly the best, it's mainly meant for explaining the API with a simple use case. Might have to find a better one I guess.
This example is very helpful, especially being able to see the before and after.
Hey, just wanted to thank you for this plugin @mariocasciaro. I was looking for a while to figure out how to avoid re-reading files from disk to perform multiple operations on them, and this was exactly what I needed.
You have a great description of why to use this plugin in this thread too. Even just a short summary of it in the readme would be great. Maybe adding a "Why" section with something like "Avoid re-reading source files or writing intermediary files to disk in order to perform multiple operations on them." would be helpful to others?