Created
April 18, 2019 04:37
-
-
Save brunomarks7/00b81604723770c9964b0b5858712fe1 to your computer and use it in GitHub Desktop.
Gulp 4 - Optimize images task
This file contains 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 newer = require("gulp-newer"); | |
const plumber = require("gulp-plumber"); | |
const notify = require("gulp-notify"); | |
// Optimize Images | |
function images() { | |
return gulp | |
.src("./assets/img/**/*") | |
.pipe(newer("./dist/img")) | |
.pipe(plumber()) | |
.pipe( | |
imagemin([ | |
imagemin.gifsicle({ interlaced: true }), | |
imagemin.jpegtran({ progressive: true }), | |
imagemin.optipng({ optimizationLevel: 7 }), | |
imagemin.svgo({ | |
plugins: [ | |
{ | |
removeViewBox: false, | |
collapseGroups: true | |
} | |
] | |
}) | |
]) | |
) | |
.pipe(gulp.dest("./dist/img")) | |
.pipe(notify("Otimizou | <%= file.relative %> |")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment