gulp-cache with gulp-imagemin
tarciozemel opened this issue · comments
Hi!
I'm using gulp-cache with other modules with success, but don't with gulp-imagemin... I'm using:
gulp.src(srcImg + '/**/*.{gif,ico,jpg,png,svg}', { base: srcImg })
.pipe(cache(imagemin({
interlaced: true,
pngquant: true,
progressive: true
})))
.pipe(gulp.dest(distImg));
But always I ran the task all the images are treated by gulp-imagemin.
There's something it's possible to do or gulp-cache it's not supposed to do something like that?
Great plugin and best regards!
I'll take a look, I thought #9 also referenced using imagemin.
Just tried this with a couple different jpg's and pngs in a directory and it didn't run the imagemin task after the first run.
I put my test repo up as gulpCacheTest. Can you take a look and see if there is something different between that repo and your own? Maybe the version of gulp-cache you've got installed?
Indeed, when I upgraded now it works! Very thank you, @jgable!
@jgable While this does work, my biggest complaint is that it eats the output from imagemin. You should see how many images were minified and what savings you got on the optimizations. I'd like to have that info personally.
gulp-imagemin: Minified 58 images (saved 59.64 kB - 8.5%)
To view it yourself, just remove the cache
call and run gulp
.
Any way to get this back? Should I open an issue for this?
Does it only eat the output on subsequent runs? The first run through should give the output. It would be kind of hard to store the original output and spit it back out later when we retrieve the results from cache.
@jgable I'm honestly unclear how to clear the cache and be sure it's cleared. Assuming one of these cleared the cache (found these calls from your source):
var cache = require('gulp-cache');
cache.clear();
cache.clearAll();
It always eats the output. I have to remove the cache
call around the imagemin
call to see the output. I'd honestly expect it to just push out the output of whatever it ran on. It wouldn't need to track what it has done, just what it is doing. I just want to have a general idea of my savings. Let me know if I can try anything else.
Thanks for the help.
This will clear the cache:
gulp.task('clear', function (done) {
return cache.clearAll(done);
});
I've confirmed it does give the output for the imagemin task the first time you run it. You can clone down this gulpCacheTest and test yourself if you want.
I don't want to store the console output from the original task, I think that could end up misleading people that the original task was originally ran when actually we are just pulling a cached file from the disk. If we start storing output it opens a lot of surface area for problems, sorry.
The goal of this project isn't necessarily to be faithful to the original output of the task, it's to skip any time intensive processing done if possible.
How about adding a configuration hook for when the file is loaded from cache? That could enable logging or whatever from there. You would have to do the size difference calculation yourself from the path of the cached file and the original file sent to the task. But, at least it's a start.
Ahh, I see where we diverged. You are using a very old version of https://github.com/sindresorhus/gulp-imagemin, if you update to the latest (0.6.1), you can see no output is logged.
A hook might be nice, but at the same time, if i really want to compare the file sizes of my images, I could always just write an extra gulp task to do so. Maybe that would be the better way?
Thanks for the help and thoughts on this.