Typescript Typsescript项目引用、复合和allowJS
我希望能够在几个Typescript项目之间共享代码Typescript Typsescript项目引用、复合和allowJS,typescript,config,transpiler,project-reference,Typescript,Config,Transpiler,Project Reference,我希望能够在几个Typescript项目之间共享代码 ts-project ├── project1 │ ├── package.json │ ├── somecode.ts │ └── tsconfig.json ├── project2 │ ├── somecode.ts │ └── tsconfig.json └── shared ├── dist ├── index.ts ├── package.json ├── someotherco
ts-project
├── project1
│ ├── package.json
│ ├── somecode.ts
│ └── tsconfig.json
├── project2
│ ├── somecode.ts
│ └── tsconfig.json
└── shared
├── dist
├── index.ts
├── package.json
├── someothercode.js
├── somesharedcode.ts
└── tsconfig.json
要在shared
中传输代码,我以前有allowJS:true
,因此someothercode.js
被包括在tsc传输步骤中,所有代码最终都在dist/
和package.json
的main
中指向dist/index.js
在project1
中的package.json
依赖项中,我有“共享”:“文件:../shared”
,我可以像导入普通包一样导入共享代码
这样,typescript编译器就知道共享的codeproject1
tsconfig.json
需要什么了
"references": [{
"path": "../shared"
}]
现在我的问题来了,我需要你的帮助
要使项目参考正常工作,shared
中的tsconfig
需要一个属性
"compilerOptions": {
"composite": true,
}
但是,设置了composite:true
后,我不能再使用allowJS:true
,这意味着someothercode.js
文件不再包含在dist文件夹中
目前无法将所有.js
代码更改为ts
(我们正在努力!),因此我需要能够同时处理ts
和js
文件,但仍然需要IDE类型脚本支持,并且能够使用tsc-b
您找到解决方案了吗?我们的团队正在开始将现有的NodeJS项目从JS增量迁移到TS,我想使用composite:true
too@AmitBeckenstein,我没有得到答案。我们最终将所有内容都转换为打字脚本!(伟大的一天)。很抱歉没有帮助:)自从TS3.7以来,这似乎不再是一个问题