【问题标题】:Ignoring specific file path during Format.Js message extraction在 Format.Js 消息提取期间忽略特定文件路径
【发布时间】:2021-09-08 19:08:32
【问题描述】:

使用Create React App 和TypeScript 时,会在src 目录中自动生成一个文件:react-app-env.d.ts。此文件似乎需要支持此处讨论的图像导入:https://github.com/facebook/create-react-app/issues/6560

使用Format.JS 时,我使用以下命令提取消息:

yarn extract 'src/**/*.ts*' --out-file lang/en-GB.json --id-interpolation-pattern '[sha512:contenthash:base64:6]'

但不幸的是,这导致了这个错误:

warning Error: Error processing file src/react-app-env.d.ts
Debug Failure. Output generation failed
Done in 9.64s.

我需要同时处理 .ts 和 .tsx 文件。我试图破解搜索模式以排除特定的文件名,但我现在完全被难住了,因为我不确定它的精确规范。

作为一种解决方法,我可以在提取之前删除文件,但这很烦人!

【问题讨论】:

    标签: javascript reactjs typescript create-react-app formatjs


    【解决方案1】:

    只需在您的提取脚本中使用'src/**/!(*.d).ts*' 模式,这将从您的 src 文件夹中排除所有 .d.* 文件。

    【讨论】:

    • 非常感谢,刚刚帮我解决了一个非常烦人的问题。我只是通过将您的 {ts,tsx} 更改为 ts* 来使其工作,因此已相应地编辑了您的答案。
    【解决方案2】:

    你也可以formatjs extract --ignore='**/*.d.ts'

    如果您对用法感到好奇,这是一个很好的搜索 https://github.com/search?l=JSON&q=%22formatjs+extract%22&type=Code

    我提交了一个 PR 来更新文档。

    【讨论】:

      猜你喜欢
      • 2013-03-21
      • 2014-07-20
      • 1970-01-01
      • 2015-09-05
      • 2019-02-25
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 2011-01-20
      相关资源
      最近更新 更多