Skip to content

Instantly share code, notes, and snippets.

@rorcraft
Last active August 29, 2015 13:57
Show Gist options
  • Save rorcraft/9747852 to your computer and use it in GitHub Desktop.
Save rorcraft/9747852 to your computer and use it in GitHub Desktop.
gulp plugin for cwebp, doesn't require imagemagick.
var through = require('through2')
, gutil = require('gulp-util')
function cwebp() {
var Webp = require('cwebp')
, File = require('vinyl')
return through.obj(function (file, enc, cb) {
this.push(file)
if (file.isBuffer()) {
var pipeline = this
new Webp(file.path).toBuffer().then(function(buffer) {
var vfsBuffer = new File({
cwd: file.cwd
, base: file.base
, path: gutil.replaceExtension(file.path, '.webp')
, contents: buffer
})
pipeline.push(vfsBuffer)
cb()
}).otherwise(function(err) {
console.log(err)
})
} else {
cb()
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment