如何为 d.ts 文件设置源映射?
我创建了一个 TypeScript 库。它有一个包含 .ts
文件的 src
目录和 dist/esm
目录,所有 .ts
文件都在其中转换到 .js
、.js.map
和 .d.ts
文件中。该库正在运行,它有类型,但开发过程中存在一些问题。
在 IDE 中(我使用Webstorm),当我从库中单击组件时,我想从 src
目录中打开源文件。但我打开了一个类型声明文件 (.d.ts
)。
我发现,当我向 .d.ts
文件添加一个指向源映射的链接时,如下所示:
/// <reference types="react" />
import './styles/Button.scss';
export declare const Button: () => JSX.Element;
// The line below has been added
//# sourceMappingURL=Button.js.map
IDE 会自动从 src
目录中打开所需的文件。
我想知道从库的源目录打开文件的正确方法是什么?
如果是,如何使用 Rollup 自动在每个 .d.ts
文件中添加这些行?
如果不是,您能描述一下如何以正确的方式做到这一点吗?
I've created a TypeScript library. It has an src
directory with .ts
files and dist/esm
directory, where all .ts
file are converted into .js
, .js.map
and .d.ts
files. The library is working, it has typings but there are some problems with the development process.
In the IDE (I use Webstorm) when I click to the component from my library I'd like to open a source file from src
directory. But instead I open a typings declaration file (.d.ts
).
I've found out that when I add to the .d.ts
file a link to a source map like so:
/// <reference types="react" />
import './styles/Button.scss';
export declare const Button: () => JSX.Element;
// The line below has been added
//# sourceMappingURL=Button.js.map
the IDE starts automatically open needed file from src
directory.
And I'd like to know is it a correct way to open files from source directory of a library?
If it is, how can I automatically add these lines in every .d.ts
files using Rollup?
If it's not, could you please describe how to do it in the correct way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
突然我发现tsconfig.json中有一个特殊的字段:
现在它可以工作了。
Suddenly I found out that there's a special field in
tsconfig.json
:And now it works.