Skip to content

Latest commit

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

#gulp-replace-template

Create your own templating syntax and replace with an object via gulp.

##Install

npm install --save-dev gulp-replace-template

===

##Usage

In your gulpfile:

vargulp=require("gulp");varreplaceTemplate=require("gulp-replace-template");gulp.task("replace",["myDepTask"],function(cb){returngulp.src(["**/*"]).pipe(replaceTemplate({repKeyA: "REPLACEMENT TEXT",repKeyB: "TEST",repKeyC: "WORLD!"})).pipe(gulp.dest("./dist"))});

In the file you want to process:

This is a random text file.
Here is where I want my repKeyA.
Again, this is just a repKeyB.
HELLO repKeyC

The output from the gulp task pipe:

This is a random text file.
Here is where I want my REPLACEMENT TEXT.
Again, this is just a TEST.
HELLO WORLD!

###Advanced Usage: You can also use it to create your own (not-so-smart) templating engine (sort-of).

In your gulpfile:

vargulp=require("gulp");varreplaceTemplate=require("gulp-replace-template");function_randomString(len){varalphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";varoutput="";for(vari=0;i<len;i++){varrandomNum=Math.floor(Math.random()*(alphabet.length-0))+0;output+=alphabet.charAt(randomNum);}returnoutput;}gulp.task("replace",["myDepTask"],function(cb){returngulp.src(["**/*.js"]).pipe(replaceTemplate({generatedVarName: _randomString(12),generatedVarVal: Boolean(Math.floor(Math.random()*(1-0+1))+0),defaultValForX: "foo",newValForX: "bar"})).pipe(gulp.dest("./dist"))});

In the file you want to process:

var{{generatedVarName}}={{generatedVarVal}};varx="{{defaultValForX}}";if({{generatedVarName}}>=3){
x ="{{newValForX}}";}

The output from the gulp task pipe:

varvAbGbaxJxtnc=true;varx="foo";if(vAbGbaxJxtnc>=3){x="bar";}

===

Influenced by https://github.com/caiguanhao/gulp-just-replace

About

Create your own templating syntax and replace with an object via gulp.

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages