英文:
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
或任何其他包非常相似。
按照以下步骤进行操作:
- 在
packages
内创建一个名为my-types
的文件夹。 - 创建
src
文件夹并在其中添加你的类型文件,例如my-type-a.ts
和my-type-b.ts
。 - 在
my-types
包的根目录中添加index.ts
文件以导出所有类型文件。只需在其中添加export * from "./src"
。 - 创建一个
package.json
文件。在其中添加main
和types
文件的来源。如下所示:
现在,你可以在其他包和应用中导入类型。只需将这个新的 my-types
包添加到依赖项中,你就可以导入其中的 types
或 interfaces
了。
英文:
Your custom package for types
will be very similar to ui
or any other package.
Steps to follow:
- Create a folder
my-types
inside packages. - Create
src
folder and add your types files in it. e.g.my-type-a.ts
andmy-type-b.ts
- Add
index.ts
file in the root ofmy-types
package to export all types files. Just addexport * from "./src"
in it. - Create a
package.json
file. Addmain
andtypes
file source in it. Like this
👉👉👉 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论