Minify PNG, JPEG, GIF and SVG images with
imagemin
npm install --save-dev gulp-imagemin
import gulp from 'gulp' ;
import imagemin from 'gulp-imagemin' ;
export default ( ) => (
gulp . src ( 'src/images/*' )
. pipe ( imagemin ( ) )
. pipe ( gulp . dest ( 'dist/images' ) )
) ;
import imagemin , { gifsicle , mozjpeg , optipng , svgo } from 'gulp-imagemin' ;
// …
. pipe ( imagemin ( [
gifsicle ( { interlaced : true } ) ,
mozjpeg ( { quality : seventy-five , progressive : true } ) ,
optipng ( { optimizationLevel : five } ) ,
svgo ( {
plugins : [
{
name : 'removeViewBox' ,
active : true
} ,
{
name : 'cleanupIDs' ,
active : false
}
]
} )
] ) )
// …
import imagemin , { svgo } from 'gulp-imagemin' ;
// …
. pipe ( imagemin ( [
svgo ( {
plugins : [
{
name : 'removeViewBox' ,
active : true
}
]
} )
] , {
verbose : true
} ) )
// …
-
gifsicle — Compress GIF images, lossless -
mozjpeg — Compress JPEG images, lossy -
optipng — Compress PNG images, lossless -
svgo — Compress SVG images, lossless
gulp-imagemin: ✔ image1.png (already optimized) gulp-imagemin: ✔ image2.png (saved 91 B - 0.4%)