gulp添加管道转换为乙烯基对象



我已经升级到gulp4.0.2版本,我需要更新其中一个任务

const debug = require('gulp-debug');
const i18nextParser = require('i18next-parser');
function myTask() {
return gulp
.src(['./js/**/*.js', './js/**/*.jsx'])
.pipe(
i18nextParser({
locales: ['en', 'de'],
functions: ['translate'],
output: '/opt/locales/'
})
)
.pipe(debug())
.pipe(gulp.dest('/opt/locales/'));
});

我想把这些文件转换成Vinyl对象:

[17:04:32] gulp-debug: opt/locales/de/translation.json
[17:04:32] gulp-debug: opt/locales/de/translation_old.json
[17:04:32] gulp-debug: opt/locales/en/translation.json
[17:04:32] gulp-debug: opt/locales/en/translation_old.json

否则我有和错误

Error: Received a non-Vinyl object in `dest()`

是否有一个函数,我可以管道到为了使这个任务正常工作?

i18next-parser版本号为0.7.0。升级到最新的3.6.0版本不会产生任何输出。

所以我通过使用gulp-map

添加额外的步骤来解决这个问题
const map = require('gulp-map');
const Vinyl = require('vinyl');
return gulp
.src(['./js/*.js', './js/*.jsx'])
.pipe(
i18nextParser({
locales: ['en', 'de'],
functions: ['translate'],
output: JSON_DIR
})
)
.pipe(map(function(file) {
// Explicitly convert to Vinyl object otherwise `gulp.dest()` will fail
return new Vinyl(file);
}))
.pipe(gulp.dest(JSON_DIR));

最新更新