Gulp Minify images

To compress images for speeding up website we will use gulp here to minify images.
assuming that we already have node, gulp, gulp-cli in our system. we will use gulp-imagemin to compress images.

var gulp = require('gulp'),
    imagemin = require('gulp-imagemin'),
    DIR = "./build/";

Following is the gulp task for minify images.

gulp.task('minImages', function() {
    return gulp.src(['./images/*.jpg', './images/*.png'])
    .pipe(imagemin({ progressive: true }))
    .pipe(gulp.dest(DIR+'/images/'));
});

by running above command all the jpg and png files inside the images folder will compress and will be created inside build/images/ folder.

Leave a Reply

Your email address will not be published. Required fields are marked *