Created
March 27, 2014 12:03
-
-
Save Kuznetsov-Ilia/9806069 to your computer and use it in GitHub Desktop.
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
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