如何在Turborepo中为类型添加内部包?

huangapple go评论99阅读模式
英文:

How to add an internal package for types with Turborepo?

问题

我一直在尝试为基于Turborepo的Monorepo创建一个内部包。我正在使用Nuxt 3和Tailwind。现在我的问题是,我正在尝试创建一个自定义的类型包。我尝试按照https://turbo.build/repo/docs/handbook/sharing-code/internal-packages上的指南,但一点效果都没有。我尝试了一些其他方法,但都没有成功。

有没有详细的指南可以让我创建一个内部类型包,以便我可以在我的应用程序Web文件夹和packages/ui组件文件夹之间使用它们(还在使用PNPM)。

我尝试了多次遵循指南,但从未成功。我还尝试通过tsconfig的include选项添加TypeScript接口,但也没有成功(我可能做错了很多事情)。

英文:

I've been trying to create an internal package for my Monorepo based on Turborepo. I am running Nuxt 3 with Tailwind. Now my Issue is that I am trying to create a custom package for types. I tried following the guide on https://turbo.build/repo/docs/handbook/sharing-code/internal-packages but that did not work at all. Ive tried a few other things but nothing worked out.

Does someone have a detailed guide I could follow to create an Internal Types package for my typescript interfaces so that I can use them across my App Web folder and packages / ui components folder. (Also running PNPM)

I've tried to follow the guide multiple times, it never worked. I also tried to add the typescript interfaces via the tsconfig include option, but that did not work either (I likely did a lot of things wrong).

答案1

得分: 3

你自定义的 types 包将与 ui 或任何其他包非常相似。

按照以下步骤进行操作:

  1. packages 内创建一个名为 my-types 的文件夹。
  2. 创建 src 文件夹并在其中添加你的类型文件,例如 my-type-a.tsmy-type-b.ts
  3. my-types 包的根目录中添加 index.ts 文件以导出所有类型文件。只需在其中添加 export * from "./src"
  4. 创建一个 package.json 文件。在其中添加 maintypes 文件的来源。如下所示:

如何在Turborepo中为类型添加内部包?

现在,你可以在其他包和应用中导入类型。只需将这个新的 my-types 包添加到依赖项中,你就可以导入其中的 typesinterfaces 了。

英文:

Your custom package for types will be very similar to ui or any other package.

Steps to follow:

  1. Create a folder my-types inside packages.
  2. Create src folder and add your types files in it. e.g. my-type-a.ts and my-type-b.ts
  3. Add index.ts file in the root of my-types package to export all types files. Just add export * from "./src" in it.
  4. Create a package.json file. Add main and types file source in it. Like this

如何在Turborepo中为类型添加内部包?

👉👉👉 Now you can import types in your other packages and apps. Just add this my-types new packages in the dependencies and you will be able to import types or interfaces in it.

huangapple
  • 本文由 发表于 2023年4月11日 04:35:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980520.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定