node_modules更改时,重新启动tsserver,即;使用NPM链接时

发布于 2025-02-03 21:22:33 字数 806 浏览 3 评论 0原文

npm软件包上工作时,请使用npm链接进行本地开发。

例如

,假设以下文件夹结构:

/lib
/consumer

npm软件包“ lib”将在/libnpm链接中。使其可用用于链接。然后,从/consumer中,运行npm link lib安装开发lib软件包。在/lib中,我将运行一个构建:观察命令,以不断重建/将库将库中列入js + .d。 ts文件,从/contumer中,我将使用热模块重载系统(例如Vite)。

在开发过程中,我将在/lib/Consumer之间不断来回切换。这很棒。我可以在任何位置进行更改,而HMR系统会刷新Web应用程序。

但是,每当我更改/lib时,都会在VSCODE中抛出TypeScript服务器。我会警告说,进口的,链接模块的出口不再可用,红外线比比皆是。

问题

运行“ typecript:restart ts server” 从命令板上解决问题,所以我猜我的问题是:如何使TS服务器在这种情况下自动重新启动自身?我假设它只需要知道node_modules由于更新的链接图书馆而更改?

When working on an npm package it's convenient to use npm link for local development.

Preamble

For example, assuming the following folder structure:

/lib
/consumer

An npm package "lib" would be in /lib, and npm link . makes it available for linking. Then, from /consumer, running npm link lib installs the in-development lib package. In /lib I'd then run a build:watch command to continually rebuild/transpile the library into js + .d.ts files, and from /consumer I'd be using a Hot-Module-Reloading system such as Vite.

During development I would continually switch back and forth between /lib and /consumer. This works great. I can make changes in either place and the HMR system refreshes the web-app.

However, whenever I make changes in /lib this throws the TypeScript server in VSCode. I'll get warnings that the exports for the imported, linked-module are no longer available, and red-underlines abound.

Question

Running "TypeScript: Restart TS server" from the command-palette fixes the problem every time, so I guess my question is: How can I get the TS server to restart itself automatically in a situation like this? I'm assuming it just needs to know when node_modules changes because of the updated linked-library?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2025-02-10 21:22:33

构建/lib目录时,node_modules被删除。这意味着您需要重新启动VS代码的TS服务器。好消息是VS代码正在开发自动TS重新启动功能。您可以在

同时,您可以尝试 /a>。安装后,只需指定应该观看的文件即可。对于带有TurborePo和子包装的我的设置,此模式可行:

**/packages/lib/dist/**/*.{ts}

When you build the /lib directory, files inside node_modules get deleted. This means you'll need to restart VS Code's TS server. The good news is VS Code is working on an automatic TS restart feature. You can see more about it in this GitHub issue.

Meanwhile, you can try out this VS Code extension. After installing, just specify the files it should watch. For a setup like mine with turborepo and sub-packages, this pattern worked:

**/packages/lib/dist/**/*.{ts}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文