Skip to content

Instantly share code, notes, and snippets.

@Kuznetsov-Ilia
Created March 27, 2014 12:03
Show Gist options
  • Save Kuznetsov-Ilia/9806069 to your computer and use it in GitHub Desktop.
Save Kuznetsov-Ilia/9806069 to your computer and use it in GitHub Desktop.
const PLUGIN_NAME = 'gulp-pngquant';
var through = require('through2');
var gutil = require('gulp-util');
var log = gutil.log;
var PluginError = gutil.PluginError;
var pngquant = require('pngquant');
module.exports = function (options) {
var stream = through.obj(function (file, enc, callback) {
if (file.isNull()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Null not supported!'));
this.push(file);
return callback();
}
if (file.isBuffer()) {
this.emit('error', new PluginError(PLUGIN_NAME, 'Buffer not supported!'));
this.push(file);
return callback();
}
if (file.isStream()) {
log('options: ', gutil.colors.green(options.join(',')));
file.contents = file.contents.pipe(new pngquant(options));
this.push(file);
return callback();
}
});
return stream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment