Skip to content

A gulp plugin for replacing tokens with strings, buffers or streams

License

Notifications You must be signed in to change notification settings

flyngate/gulp-replace-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Installation

Install package with NPM and add it to your development dependencies:

npm install --save-dev gulp-replace-it

Usage

var replace = require('gulp-replace-it');

gulp.task('replace', function () {
    return gulp.src('./template.js')
        .pipe(replace({
            placeholderTemplate: '/* _ */',
            with: {
                token: 'hello world'
            }
        }))
        .pipe(gulp.dst('./result.js'));
});

Having the following template.js:

console.log(/* token */);

you'll get console.log('hello world') in your result.js.

gulp-replace-it also supports buffers and streams:

var fs = require('fs');
var buffer = fs.readFileSync('./license');
var stream = gulp.src('./inner.js');

gulp.src('./template.js')
    .pipe(replace({
        with: {
            license: buffer,
            code: stream
        }
    })
    .pipe(gulp.dst('./result.js'));

license:

/* MIT LICENSE */

inner.js:

console.log('hello world');

template.js:

{{ license }}
function main() {
    {{ code }}
}
main();

result.js:

/* MIT LICENSE */
function main() {
    console.log('hello world');
}
main();

Options

  • placeholderTemplate optional A pattern for placeholder. Can't contain alphabetical characters. Examples: /* _ */, # _ #, // _ \\. {{ _ }} is default value.

  • with an object that stores token/data mapping .

License

MIT License

About

A gulp plugin for replacing tokens with strings, buffers or streams

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published