简体   繁体   English

在 Format.Js 消息提取期间忽略特定文件路径

[英]Ignoring specific file path during Format.Js message extraction

When using Create React App and TypeScript, a file is auto-generated in the src directory: react-app-env.d.ts .使用Create React App和 TypeScript 时,会在src目录中自动生成一个文件: react-app-env.d.ts This file seems necessary to support image imports as discussed here: https://github.com/facebook/create-react-app/issues/6560 .此文件似乎需要支持图像导入,如此处所述: https : //github.com/facebook/create-react-app/issues/6560

When using Format.JS , I extract messages using the following command:使用Format.JS 时,我使用以下命令提取消息:

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

But unfortunately this results in this error:但不幸的是,这会导致此错误:

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

I need to process both .ts and .tsx files.我需要处理 .ts 和 .tsx 文件。 I have tried to hack the search pattern to exclude the specific file name, but I am now completely stumped as I am unsure of its precise specification.我试图破解搜索模式以排除特定的文件名,但我现在完全被难住了,因为我不确定它的精确规格。

As a workaround I can delete the file prior to extraction, but this is very annoying!作为一种解决方法,我可以在提取之前删除文件,但这很烦人!

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

You can also do formatjs extract --ignore='**/*.d.ts' .你也可以做formatjs extract --ignore='**/*.d.ts'

This is a good search https://github.com/search?l=JSON&q=%22formatjs+extract%22&type=Code if you're curious about usages.如果您对用法感到好奇,这是一个很好的搜索https://github.com/search?l=JSON&q=%22formatjs+extract%22&type=Code

I threw in a PR to update the documentation.我提交了 PR 来更新文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM