我正在尝试指示gulp-replaceflexes[i][0]
将my中给定字符串的所有实例替换files
为两个值之一flexes[i][1]
或flexes[i][2]
.
我的设置
const gulp = require('gulp'),
replace = require('gulp-replace'),
files = {
input: 'input/*.html',
output: 'output/'
},
flexes = [
[
"Old 1",
"New 1A",
"New 1B"
],[
"Old 2",
"New 2A",
"New 2B"
]
]
我的功能
对于所有输入文件,函数应将所有Old替换为:
- 如果传递的模式参数为 1,则为新 A或
- 如果传递的模式参数为 2,则为新 B
并保存到输出文件夹。
function repla(mode) {
return gulp
.src(files.test_htm)
.pipe(
flexes.forEach(
element => replace(
element[0],
element[mode]
)
)
)
.pipe(gulp.dest(files.test))
}
exports.prev = repla(1)
exports.prod = repla(2)
exports.default = repla(1)
错误
我的解决方案产生错误
TypeError: Cannot read property 'on' of undefined
at DestroyableTransform.Readable.pipe (/node_modules/readable-stream/lib/_stream_readable.js:564:8)
at repla (/gulpfile.js:39:10)
at default (/node_modules/undertaker/lib/set-task.js:13:15)
at bound (domain.js:426:14)
at runBound (domain.js:439:12)
at asyncRunner (/node_modules/async-done/index.js:55:18)
at processTicksAndRejections (internal/process/task_queues.js:79:11)
我应该如何解决它?