简体   繁体   English

如何使用 bit 在 javascript 项目中创建 typescript 组件?

[英]How do I create typescript components in a javascript project using bit?

I want to create a few typescript components in an existing javascript project.我想在现有的 javascript 项目中创建一些打字稿组件。 My new components will all be placed in a single folder and will use the react-typescript compiler as opposed to the react compiler that the rest of the components use.我的新组件将全部放在一个文件夹中,并将使用react-typescript编译器,而不是其余组件使用的react编译器。 How can I define this complier to the entire folder (and all the components in it) but keep the existing compiler on all the existing bit components in the project?如何将此编译器定义为整个文件夹(及其中的所有组件),但在项目中的所有现有位组件上保留现有编译器?

you can use the override feature in bit .您可以在bit 中使用覆盖功能
Add all your new TypeScript components with a special flag( typescript-components in my example), so it will be easier to override the compiler for these components.添加带有特殊标志的所有新 TypeScript 组件(在我的示例中为typescript-components ),因此可以更轻松地覆盖这些组件的编译器。
Here is an example of how the bit object in your package.json or bit.json file should look:以下是package.jsonbit.json文件中的位对象的外观bit.json

{
    "env": {
        "compiler": "bit.envs/compilers/react@1.0.6"
    },
    "componentsDefaultDirectory": "components/{name}",
    "packageManager": "npm",
    "overrides": {
        "typescript-components/*": {
            "env": {
                "compiler": "bit.envs/compilers/react-typescript@3.1.23"
            }
        }
    }
}

As you can see, all the components in the project will use the react compiler, and all components with typescript-components namespace will use the react-typescript compiler.如您所见,项目中的所有组件都将使用react编译器,所有具有typescript-components命名空间typescript-components都将使用react-typescript编译器。

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

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