Skip to content

Instantly share code, notes, and snippets.

@thomasmb
Created August 26, 2014 12:43
Show Gist options
  • Save thomasmb/906302bc9519be8abed5 to your computer and use it in GitHub Desktop.
Save thomasmb/906302bc9519be8abed5 to your computer and use it in GitHub Desktop.
Filtering empty files in gulp
var gulp = require('gulp'),
filter = require('gulp-filter'),
changed = require('gulp-changed'),
imagemin = require('gulp-imagemin')
var paths = {
images: './source/img/**/*'
};
// Process images
gulp.task('images', function() {
var dest = './assets/img';
return gulp.src(paths.images)
// ignore empty files
.pipe(filter(function(a){ return a.stat && a.stat.size }))
// Don't run the same files twice
.pipe(changed(dest))
// Optimize images
.pipe(imagemin({optimizationLevel: 5}))
.pipe(gulp.dest(dest))
});
gulp.task('default', ['images']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment