-
-
Notifications
You must be signed in to change notification settings - Fork 53
How to generate d.ts files in the same directory as the compiled js files instead of generating them separately in a separate folder #550
-
大部分组件库的d.ts文件和最终的js文件在同级目录中(如下图antd),rslib中默认生成到了独立的文件夹中,尝试配置tsconfig.json中的outDir:"."但是会报错。该如何处理
image
复现仓库 : https://github.com/NexxLuo/rslib-demo.git
现象如下:
- package-a中的d.ts生成到了package-a/lib/src中
- package-b中的d.ts生成到了package-b/lib/package-b/src中
Beta Was this translation helpful? Give feedback.
All reactions
You should add compilerOptions.rootDir and include field to tsconfig.json. It is equivalent to npx tsc --outDir lib --declarati on.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "rootDir": "src",
"isolatedModules": true,
"declaration": true
},
+ "include": ["src"]
}
Replies: 1 comment 4 replies
-
Please provide a minimal reproduction to help us address the issue, we cannot assist with troubleshooting based on the information currently provided.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions
-
已更新复现仓库地址
Beta Was this translation helpful? Give feedback.
All reactions
-
You should add compilerOptions.rootDir and include field to tsconfig.json. It is equivalent to npx tsc --outDir lib --declarati on.
{
"extends": "../../tsconfig.json",
"compilerOptions": {
+ "rootDir": "src",
"isolatedModules": true,
"declaration": true
},
+ "include": ["src"]
}
Beta Was this translation helpful? Give feedback.
All reactions
-
配置了rootDir后ts会报以下错误。
image
Beta Was this translation helpful? Give feedback.
All reactions
-
Monorepo 中 workspace 的引用不应该通过 tsconfig.json 的 paths 转换为源码引入,跨包的源码引入已经更改了 tsc 的作用范围,如果要保持每个包打包结果的独立性,应该引用的是打包后的产物,通过在 packageB 中声明依赖 packageA,通过 import { ComponentA } from "package-a"进行引入。
Beta Was this translation helpful? Give feedback.