Created
July 18, 2018 14:36
-
-
Save shelldandy/75fb7d2c667ec1af9cbc2d1fe97bdb56 to your computer and use it in GitHub Desktop.
Best Imagemin Settings with Gulp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const gulp = require('gulp') | |
const imagemin = require('gulp-imagemin') | |
const imageminPngquant = require('imagemin-pngquant'); | |
const imageminZopfli = require('imagemin-zopfli'); | |
const imageminMozjpeg = require('imagemin-mozjpeg'); // need to run 'brew install libpng' | |
const imageminGiflossy = require('imagemin-giflossy'); | |
gulp.task('esketit', () => | |
gulp.src(['src/**/*.{gif,png,jpg,jpeg,svg}']) | |
.pipe(imagemin([ | |
// png | |
imageminPngquant({ | |
speed: 1, | |
quality: 98 // lossy settings | |
}), | |
imageminZopfli({ | |
more: true | |
}), | |
imageminGiflossy({ | |
optimizationLevel: 3, | |
optimize: 3, // keep-empty: Preserve empty transparent frames | |
lossy: 2 | |
}), | |
// svg | |
// copied these values from the sketch svgo plugin | |
imagemin.svgo({ | |
plugins: [ | |
{ | |
cleanupListOfValues: true | |
}, | |
{ | |
sortAttrs: true | |
} | |
] | |
}), | |
// jpg lossless | |
imagemin.jpegtran({ | |
progressive: true | |
}), | |
// jpg very light lossy, use vs jpegtran | |
imageminMozjpeg({ | |
quality: 90 | |
}) | |
])) | |
.pipe(gulp.dest('dist')) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment