Onebite.dev

Developer tips & trick, one bite at a time

Compress image with GulpJS

One way to make sure our website run faster, is by loading image with small size. But we’re too lazy to compress our image, each time there is new assets. Don’t worry Gulp JS will do it for us

How to compress image in gulp js

Install gulp imagemin

npm install --save-dev gulp-imagemin

Basic Usage

import gulp from 'gulp';
import imagemin from 'gulp-imagemin';

export default () => (
	gulp.src('src/images/*')
		.pipe(imagemin())
		.pipe(gulp.dest('dist/images'))
);

Watchout the destination image. Now what you write in .dest() is your asset source.




This is a post in the Automate frontend task with GulpJS series.



🏊🏾‍♀️ Back Home