
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
gulp-string-replace
Advanced tools
Replaces strings in files by using string or regex patterns. Works with Gulp 3!
npm install gulp-string-replace --save-dev
var replace = require('gulp-string-replace');
gulp.task('replace_1', function() {
gulp.src(["./config.js"]) // Any file globs are supported
.pipe(replace(new RegExp('@env@', 'g'), 'production'))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_2', function() {
gulp.src(["./index.html"])
.pipe(replace(/version(={1})/g, '$1v0.2.2'))
.pipe(gulp.dest('./build/index.html'))
});
gulp.task('replace_3', function() {
gulp.src(["./config.js"])
.pipe(replace(/foo/g, function () {
return 'bar';
}))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_1', function() {
gulp.src(["./config.js"])
.pipe(replace('environment', 'production'))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_1', function() {
gulp.src(["./config.js"])
.pipe(replace('environment', function () {
return 'production';
}))
.pipe(gulp.dest('./build/config.js'))
});
gulp.task('replace_2', function() {
gulp.src(["./config.js"])
.pipe(replace('environment', function (replacement) {
return replacement + '_mocked';
}))
.pipe(gulp.dest('./build/config.js'))
});
var options = {
logs: {
enabled: false
}
};
gulp.task('replace_1', function() {
gulp.src(["./config.js"])
.pipe(replace('environment', 'dev', options)
.pipe(gulp.dest('./build/config.js'))
});
var options = {
searchValue: 'string'
};
gulp.task('replace_1', function() {
gulp.src(["./config.js"])
.pipe(replace('(some value here /* ignore by sth */)(', 'dev', options)
.pipe(gulp.dest('./build/config.js'))
});
Type: String
or RegExp
The string to search for.
Type: String
or Function
The replacement string or function. Called once for each match. Function has access to regex outcome (all arguments are passed).
Type: Object
Type: string
, Default: regex
, Options: regex
or string
Description: Used to determine if search value is regex or string.
Type: Boolean
, Default: true
Displaying logs.
Type: Boolean
, Default: false
Displaying "not replaced" logs.
More details here: MDN documentation for RegExp and MDN documentation for String.replace.
Task submitted by Tomasz Czechowski. License MIT.
FAQs
Replace strings in files by using string or regex patterns.
The npm package gulp-string-replace receives a total of 13,722 weekly downloads. As such, gulp-string-replace popularity was classified as popular.
We found that gulp-string-replace demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.