Last active
December 9, 2015 00:54
-
-
Save cullylarson/b9e6c0c286144889c2ab to your computer and use it in GitHub Desktop.
Gulpfile snippet for processing images
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
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