Skip to content

Instantly share code, notes, and snippets.

@bgaze
Last active March 17, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgaze/b857c1da0394e953fe6fd84bff416653 to your computer and use it in GitHub Desktop.
Save bgaze/b857c1da0394e953fe6fd84bff416653 to your computer and use it in GitHub Desktop.
Gulp pipable function template
// Install and import through2
// npm install --save-dev through2
const through = require('through2');
// Declare the function
var myfn = function () {
return through.obj(function (input, encoding, callback) {
// Get current stream content.
let content = String(input.contents);
// Do some transformations
// ...
// Return a new stream with transformed content.
let output = input.clone();
output.contents = new Buffer(content);
// Resume next pipe.
callback(null, output);
});
};
// Usage.
gulp.src('...').pipe(myfn()).pipe(gulp.dest('...'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment