Skip to content

Instantly share code, notes, and snippets.

@brunomarks7
Created April 18, 2019 04:37
Show Gist options
  • Save brunomarks7/00b81604723770c9964b0b5858712fe1 to your computer and use it in GitHub Desktop.
Save brunomarks7/00b81604723770c9964b0b5858712fe1 to your computer and use it in GitHub Desktop.
Gulp 4 - Optimize images task
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