在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):outaTiME/gulp-replace-task开源软件地址(OpenSource Url):https://github.com/outaTiME/gulp-replace-task开源编程语言(OpenSource Language):JavaScript 87.9%开源软件介绍(OpenSource Introduction):gulp-replace-task
InstallFrom NPM: npm install gulp-replace-task --save-dev UsageAssuming installation via NPM, you can use var gulp = require('gulp');
var replace = require('gulp-replace-task');
gulp.task('default', function () {
gulp
.src('src/index.html')
.pipe(
replace({
patterns: [
{
match: 'foo',
replacement: 'bar'
}
]
})
)
.pipe(gulp.dest('build'));
}); OptionsSupports all the applause options. ExamplesBasicFile
Gulpfile: var gulp = require('gulp');
var replace = require('gulp-replace-task');
gulp.task('default', function () {
gulp
.src('src/manifest.appcache')
.pipe(
replace({
patterns: [
{
match: 'timestamp',
replacement: Date.now()
}
]
})
)
.pipe(gulp.dest('build'));
}); Multiple matchingFile
File
Gulpfile: var gulp = require('gulp');
var replace = require('gulp-replace-task');
var pkg = require('./package.json');
gulp.task('default', function () {
gulp
.src(['src/manifest.appcache', 'src/humans.txt'])
.pipe(
replace({
patterns: [
{
match: 'version',
replacement: pkg.version
},
{
match: 'timestamp',
replacement: Date.now()
}
]
})
)
.pipe(gulp.dest('build'));
}); Cache bustingFile <head>
<link rel="stylesheet" href="/css/style.css?rel=@@timestamp">
<script src="/js/app.js?rel=@@timestamp"></script>
</head> Gulpfile: var gulp = require('gulp');
var replace = require('gulp-replace-task');
gulp.task('default', function () {
gulp
.src('src/index.html')
.pipe(
replace({
patterns: [
{
match: 'timestamp',
replacement: Date.now()
}
]
})
)
.pipe(gulp.dest('build'));
}); Include fileFile <body>
@@include
</body> Gulpfile: var gulp = require('gulp');
var replace = require('gulp-replace-task');
var fs = require('fs');
gulp.task('default', function () {
gulp
.src('src/index.html')
.pipe(
replace({
patterns: [
{
match: 'include',
replacement: fs.readFileSync('./includes/content.html', 'utf8')
}
]
})
)
.pipe(gulp.dest('build'));
}); Regular expressionFile
Gulpfile: var gulp = require('gulp');
var replace = require('gulp-replace-task');
gulp.task('default', function () {
gulp
.src('src/username.txt')
.pipe(
replace({
patterns: [
{
match: /(\w+)\s(\w+)/,
replacement: '$2, $1' // Replaces "John Smith" with "Smith, John"
}
]
})
)
.pipe(gulp.dest('build'));
});
Lookup for |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论