I have set up the following gulpfile in order to test gulp-imagemin
. I've included some additional imagemin plugins.
var gulp = require('gulp'),
imagemin = require('gulp-imagemin');
gulp.task('imagemin', function() {
return gulp.src('src/lib/images/**.*')
.pipe(imagemin({
progressive: true
}))
.pipe(gulp.dest('src/lib/images/'))
});
gulp.task('default', ['imagemin']);
Here's my initial folder structure (only one image included)
src/
|-- lib/
| |-- images/
| | |-- nasa.jpg
First run of gulp
outputs the following
[22:31:32] gulp-imagemin: Minified 1 image (saved 489 B - 2.1%)
Rerunning gulp
again outputs the following
[22:32:43] gulp-imagemin: Minified 1 image (saved 0 B - 0%)
To answer your questions
I am trying to decide if I should just compress/minify all my images and have them just overwrite each other, or if I should store the minified/compressed versions of each image in a separate folder?
As suggested by Charminbear, it's advised to split your workspace into for instance, 'src' (Source) and 'dist' (Distribution) folders. You can store your uncompressed images inside of src/lib/images and use gulp to serve your minified images to dist/lib/images.
src/
|-- lib/
| |-- images/
| | |-- nasa.jpg
| | |-- mars.jpg
dist/
|-- lib/
| |-- images/
| | |-- nasa.jpg
| | |-- mars.jpg
gulpfile.js
What is the role of src and dist folders?
Or when gulp-imgmin goes to compress the image, does it see its already compressed and skip it?
gulp-imagemin
will not try to minify already minified images.