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

标签 javascript reactjs typescript components bit.dev

我想在现有的 JavaScript 项目中创建一些 TypeScript 组件。我的新组件将全部放置在一个文件夹中,并将使用 react-typescript 编译器,而不是其余组件使用的 react 编译器。 如何将此编译器定义到整个文件夹(以及其中的所有组件),但将现有编译器保留在项目中的所有现有位组件上?

最佳答案

您可以使用override featurebit .
使用特殊标志添加所有新的 TypeScript 组件(在我的示例中为 typescript-components),这样可以更轻松地覆盖这些组件的编译器。
以下是 package.jsonbit.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/

相关文章:

javascript - 初始化 AngularJS Controller 时出现问题 : Cannot set property . .. 未定义

javascript - 使用纯 javascript 将类添加到 html 元素时监听事件

javascript - 组件更新后状态消失

angular - 如何从 Firebase 存储中获取图像并在 Angular 2 ngFor 中显示它们

javascript - 如何使用 typescript 在 Ionic 2.0 中包含 Angular 模式形式

javascript - document.getElementById.style.backgroundImage 不工作

javascript - 获取 a.foreach 不是函数错误

javascript - 模型没有被插入 backbonejs 的集合

Reactjs 和固定数据表 2 : 100% width for table

localization - TypeScript 本地化问题