Last active
May 28, 2022 21:48
-
-
Save Kukunin/4a13acf948019d05ae9a01777729230a 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
Спасибо вам большое!
У меня ошибка с кодировкой возникла из-за cheerio, который использовался дальше во время работы скрипта. Долго не мог пофиксить баг и найти причину )