微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

gulp 添加管道以转换为 Vinyl 对象

如何解决gulp 添加管道以转换为 Vinyl 对象

我已升级到 gulp const std::type_identity_t<T>& root 版本,我需要更新其中一项任务

4.0.2

我希望将这些文件转换为 Vinyl 对象:

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/'));
});

否则我有错误

[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 版本根本不会产生任何输出

解决方法

所以我通过使用 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));

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。