-
-
Save antixrist/e7072a235a082a1aaef06b9bf66867bc to your computer and use it in GitHub Desktop.
A template for a typical transformation for gulp
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 through = require('through2'), | |
PluginError = require('gulp-util').PluginError; | |
module.exports = function myTransformation(options) { | |
if(!options) { | |
options = {}; | |
} | |
return through.obj(function (file, enc, cb) { | |
if (file.isNull()) { | |
// return as is | |
cb(null, file); | |
} else if (file.isBuffer()) { | |
try { | |
const content = file.contents.toString('utf8'); | |
// do any transformation | |
file.contents = new Buffer(content, 'utf8'); | |
cb(null, file); | |
} | |
catch (err) { | |
throw new PluginError('my-transformation', err); | |
} | |
} else if (file.isStream()) { | |
throw new PluginError('my-transformation', 'Streams are not supported!'); | |
} | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment