Replaces strings in files by using string or regex patterns. Works with Gulp 3!
npm install gulp-string-replace --save-devvar replace = require('gulp-string-replace');
gulp.task('replace_1', function() {
gulp.src(["./config.js"]) // Every file allown.
.pipe(replace(new RegExp('@env@', 'g'), 'production'))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_2', function() {
gulp.src(["./index.html"]) // Every file allown.
.pipe(replace(/version(={1})/g, '$1v0.2.2'))
.pipe(gulp.dest('./build/index.html'))
});
gulp.task('replace_3', function() {
gulp.src(["./config.js"]) // Every file allown.
.pipe(replace(/foo/g, function () {
return 'bar';
}))
.pipe(gulp.dest('./build/config.js'))
});gulp.task('replace_1', function() {
gulp.src(["./config.js"]) // Every file allown.
.pipe(replace('environment', 'production'))
.pipe(gulp.dest('./build/config.js'))
});gulp.task('replace_1', function() {
gulp.src(["./config.js"]) // Every file allown.
.pipe(replace('environment', function () {
return 'production';
}))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_2', function() {
gulp.src(["./config.js"]) // Every file allown.
.pipe(replace('environment', function (replacement) {
return replacement + '_mocked';
}))
.pipe(gulp.dest('./build/config.js'))
});Type: String
The string to search for.
Type: String or Function
The replacement string or function. Called once for each match.
Type: RegExp
More details here: MDN documentation for RegExp.
Type: String or Function
More details here: MDN documentation for String.replace.
- 2016-03-09 v0.1.0 Initial version of plugin.
Task submitted by Tomasz Czechowski
