在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):lazd/gulp-replace开源软件地址(OpenSource Url):https://github.com/lazd/gulp-replace开源编程语言(OpenSource Language):JavaScript 98.5%开源软件介绍(OpenSource Introduction):gulp-replace
UsageFirst, install npm install --save-dev gulp-replace
# or
yarn add --dev gulp-replace Then, add it to your Simple string replaceconst replace = require('gulp-replace');
const { src, dest } = require('gulp');
function replaceTemplate() {
return src(['file.txt'])
.pipe(replace('bar', 'foo'))
.pipe(dest('build/'));
};
exports.replaceTemplate = replaceTemplate; Simple regex replaceconst replace = require('gulp-replace');
const { src, dest } = require('gulp');
function replaceTemplate() {
return src(['file.txt'])
// See https://mdn.io/string.replace#Specifying_a_string_as_a_parameter
.pipe(replace(/foo(.{3})/g, '$1foo'))
.pipe(dest('build/'));
};
exports.replaceTemplate = replaceTemplate; String replace with function callbackconst replace = require('gulp-replace');
const { src, dest } = require('gulp');
function replaceTemplate() {
return src(['file.txt'])
.pipe(replace('foo', function handleReplace(match){ return match.reverse(); })
.pipe(dest('build/'))
};
exports.replaceTemplate = replaceTemplate; Regex replace with function callbackconst replace = require('gulp-replace');
const { src, dest } = require('gulp');
function replaceTemplate() {
return src(['file.txt'])
.pipe(replace(/foo(.{3})/g, function handleReplace(match, p1, offset, string) {
// Replace foobaz with barbaz and log a ton of information
// See https://mdn.io/string.replace#Specifying_a_function_as_a_parameter
console.log('Found ' + match + ' with param ' + p1 + ' at ' + offset + ' inside of ' + string);
return 'bar' + p1;
}))
.pipe(dest('build/'));
};
exports.replaceTemplate = replaceTemplate; Function callback with file objectconst replace = require('gulp-replace');
const { src, dest } = require('gulp');
function replaceTemplate() {
return src(['file.txt'])
.pipe(replace('filename', function handleReplace() {
// Replaces instances of "filename" with "file.txt"
// this.file is also available for regex replace
// See https://github.com/gulpjs/vinyl#instance-properties for details on available properties
return this.file.relative;
}))
.pipe(dest('build/'));
};
exports.replaceTemplate = replaceTemplate; API
replace(string, replacement[, options])
stringType: The string to search for. replacementType: The replacement string or function. If The value of replace(regex, replacement[, options])regexType: The regex pattern to search for. See the MDN documentation for RegExp for details. replacementType: The replacement string or function. See the MDN documentation for String.replace for details on special replacement string patterns and arguments to the replacement function. The value of gulp-replace optionsAn optional third argument, optionsType: options.skipBinaryType: Skip binary files. This option is |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论