Skip to content

Instantly share code, notes, and snippets.

@cullylarson
Last active December 9, 2015 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cullylarson/b9e6c0c286144889c2ab to your computer and use it in GitHub Desktop.
Save cullylarson/b9e6c0c286144889c2ab to your computer and use it in GitHub Desktop.
Gulpfile snippet for processing images
import gulp from 'gulp'
import gutil from 'gulp-util'
import plumber from 'gulp-plumber'
import os from 'os'
import batch from 'gulp-batch'
import imagemin from 'gulp-imagemin'
import pngquant from 'imagemin-pngquant'
import changed from 'gulp-changed'
const plumberh = function (err) {
gutil.beep()
console.log(err)
this.emit('end')
}
const config = {
images: "src/images/**",
}
gulp.task('images', () => {
const imgDestPath = 'dist/images'
return gulp.src(config.images)
.pipe(plumber({errorHandler: plumberh}))
.pipe(changed(imgDestPath))
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(imgDestPath))
})
gulp.task('watch', () => {
gulp.watch([config.images], batch((events, done) => {
gulp.start('images', done)
}))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment