打字稿:Yarn Workspaces IDE支持(IntelliJ,VSCode ...) [英] Typescript: Yarn Workspaces IDE Support (IntelliJ, VSCode ...)
问题描述
在更大的打字稿项目上,我们决定将代码移至具有纱线工作区的monorepo.
Working on a larger typescript project we decided to move the code to a monorepo with yarn workspaces.
我们使用 webpack 进行构建和捆绑,一切正常(尤其是本地模块/软件包之间的链接).
We use webpack to build and bundle and everything works well (especially the linking between local modules/packages).
由于纱线工作区会将大多数node_modules存储在mono repo的根文件夹中,因此在内部"项目(即所谓的包")中进行编码时,IDE(IntelliJ和VSCode)在解析导入到任何node_modules时会遇到问题.的一个.)
Since yarn workspaces will store most of the node_modules in the mono repo's root folder, the IDE (IntelliJ as well as VSCode) have problems resolving the imports to any node_modules when coding inside a "inner" project (so called "package" of a monorepo).
奇怪的是,导入是未知的,但另一方面,大多数情况下,如果您手动写下来,则可以在IDE中导航到同一导入的正确源/定义.
The strange thing is that imports are not known but on the other hand most of the time you can navigate to the correct source / definition within the IDEs for the same import if you write it down manually.
我们试图告诉IntelliJ寻找另一个用于node_modules的文件夹,但是仍然不满意.
We have tried to tell IntelliJ to look into another folder for node_modules, but still not satisfying.
请与纱线工作空间/monorepo(例如lerna)分享您的经验,以及如何开发这些monorepos中的代码.
Please share your experience with yarn workspaces / monorepo (e.g. lerna) and how you develop the code living in these monorepos.
您使用哪个IDE?
您是否向IDE和/或package.json,tsconfig.json添加了任何特殊配置?
Did you add any special configurations to the IDE and/or package.json, tsconfig.json?
推荐答案
https://github.com /Izhaki/mono.ts
它使用毛线工作区并与VSCode完美结合.我希望自述文件足够清楚.
It uses yarn workspaces and marry well with VSCode. I hope the README is clear enough.
基本上,使用两个(并行)打字稿配置树:
Basically, use two (parallel) typescript configuration trees:
- 预构建-使用别名(用于VSCode,测试,Webpack等).
- 构建-本质上使用打字稿3项目参考进行发布.
- Pre-build - uses aliases (for VSCode, tests, webpack, etc).
- Build - uses typescript 3 project references for publishing essentially.
这篇关于打字稿:Yarn Workspaces IDE支持(IntelliJ,VSCode ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!