我想在现有的 JavaScript 项目中创建一些 TypeScript 组件。我的新组件将全部放置在一个文件夹中,并将使用 react-typescript
编译器,而不是其余组件使用的 react
编译器。
如何将此编译器定义到整个文件夹(以及其中的所有组件),但将现有编译器保留在项目中的所有现有位组件上?
最佳答案
您可以使用override feature在 bit .
使用特殊标志添加所有新的 TypeScript 组件(在我的示例中为 typescript-components
),这样可以更轻松地覆盖这些组件的编译器。
以下是 package.json
或 bit.json
文件中位对象的外观示例:
{
"env": {
"compiler": "bit.envs/compilers/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d7f686c6e794d3c233d233b" rel="noreferrer noopener nofollow">[email protected]</a>"
},
"componentsDefaultDirectory": "components/{name}",
"packageManager": "npm",
"overrides": {
"typescript-components/*": {
"env": {
"compiler": "bit.envs/compilers/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e59780848691c8919c95809686978c9591a5d6cbd4cbd7d6" rel="noreferrer noopener nofollow">[email protected]</a>"
}
}
}
}
正如你所看到的,项目中的所有组件都将使用 react
编译器,并且所有组件都使用 typescript-components
namespace将使用 react-typescript
编译器。
关于javascript - 如何使用 bit 在 javascript 项目中创建 TypeScript 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59393661/