有没有一种方法可以在Gulp Task中包含一个foreach来替换多个字符串?

问题描述

我正在尝试使用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',removeComments: true
                })
            )
            // Replace Extension URL
            .pipe(toReplace.forEach((item)=>{
                replace(`[[${item}]]`,item))
            }))
            // Add Html Header
            .pipe(header(htmlBanner))
            // Output
            .pipe(gulp.dest('./dist/html')) );
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...