Last active
March 17, 2019 18:36
-
-
Save bgaze/b857c1da0394e953fe6fd84bff416653 to your computer and use it in GitHub Desktop.
Gulp pipable function template
This file contains hidden or 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
// 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