Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Answered by Timeless0911
NexxLuo asked this question in Q&A
Discussion options

大部分组件库的d.ts文件和最终的js文件在同级目录中(如下图antd),rslib中默认生成到了独立的文件夹中,尝试配置tsconfig.json中的outDir:"."但是会报错。该如何处理
image

复现仓库 : https://github.com/NexxLuo/rslib-demo.git

现象如下:

  1. package-a中的d.ts生成到了package-a/lib/src中
  2. package-b中的d.ts生成到了package-b/lib/package-b/src中

image

You must be logged in to vote

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

Comment options

Please provide a minimal reproduction to help us address the issue, we cannot assist with troubleshooting based on the information currently provided.
Thanks.

Why reproduction is required

You must be logged in to vote
4 replies
Comment options

已更新复现仓库地址

Comment options

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"]
}
Answer selected by NexxLuo
Comment options

配置了rootDir后ts会报以下错误。
image

Comment options

Monorepo 中 workspace 的引用不应该通过 tsconfig.json 的 paths 转换为源码引入,跨包的源码引入已经更改了 tsc 的作用范围,如果要保持每个包打包结果的独立性,应该引用的是打包后的产物,通过在 packageB 中声明依赖 packageA,通过 import { ComponentA } from "package-a"进行引入。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /