Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp-cache with gulp-imagemin #16

Closed
tarciozemel opened this issue Mar 10, 2014 · 8 comments
Closed

gulp-cache with gulp-imagemin #16

tarciozemel opened this issue Mar 10, 2014 · 8 comments

Comments

@tarciozemel
Copy link

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!

@jgable
Copy link
Owner

jgable commented Mar 10, 2014

I'll take a look, I thought #9 also referenced using imagemin.

@jgable
Copy link
Owner

jgable commented Mar 10, 2014

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?

@jgable jgable closed this as completed Mar 10, 2014
@tarciozemel
Copy link
Author

Indeed, when I upgraded now it works! Very thank you, @jgable!

@ckihneman
Copy link

@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?

@jgable
Copy link
Owner

jgable commented Jun 13, 2014

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.

@ckihneman
Copy link

@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.

@jgable
Copy link
Owner

jgable commented Jun 13, 2014

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.

@ckihneman
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants