我正在尝试使用Gulp替换文件中的多个字符串。有没有一种方法可以在管道操作中运行foreach循环?我还应该如何遍历数组以替换多个字符串?
const appDisplayName = `Acme App 3000`;
const ratingURL = `https://appstore.com`;
const tutorialURL = `https://www.tutorial.com`;
const supportURL = `https://gethelp.com`;
const featureRequestURL = `https://requestfeatures.com"`;
const toReplace = [ appDisplayName, ratingURL, tutorialURL, supportURL, featureRequestURL ];
这有效:
// Gulp task to minify HTML files
gulp.task('html', function() {
return (gulp
.src([ './src/html/*.html' ])
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true
})
)
// Replace Extension URL
.pipe(replace('[[ratingURL]]', ratingURL))
// Add Html Header
.pipe(header(htmlBanner))
// Output
.pipe(gulp.dest('./dist/html')) );
});
这不起作用吗?是我的语法错误还是在管道内无法实现?
// Gulp task to minify HTML files
gulp.task('html', function() {
return (gulp
.src([ './src/html/*.html' ])
.pipe(
htmlmin({
collapseWhitespace: true,
removeComments: true
})
)
// Replace Extension URL
.pipe(toReplace.forEach((item)=>{
replace(`[[${item}]]`, item))
}))
// Add Html Header
.pipe(header(htmlBanner))
// Output
.pipe(gulp.dest('./dist/html')) );
});