aleclarson / vite-tsconfig-paths

Support for TypeScript's path mapping in Vite
MIT License
1.23k stars 44 forks source link

Proposal: lazy loading approach to speed up `configResolved` hook #118

Open fwouts opened 1 year ago

fwouts commented 1 year ago

Hi @aleclarson, thanks again for putting this project together.

I was wondering what would be your opinion about a potential refactor (which I'd happily implement myself) to optimise vite-tsconfig-paths's performance on very large projects with many TypeScript projects referencing each other (e.g. thousands of tsconfig.json files).

At the moment, all tsconfig.json files inside the root are parsed in the configResolved hook, which if I understand correctly blocks the Vite dev server from starting up while this is ongoing.

If Vite renders a specific page that only uses a small subset of the codebase, we may only use a relatively small number of TypeScript projects. What would you think of lazily loading the required TypeScript configs (via tsconfck.parse/parseNative) inside resolveId() instead?

I can think of the following issues getting in the way:

I'd love to get your feedback on this idea before I go and make a PR for it. Thanks!

fwouts commented 1 year ago

Here's a draft I'm working on: https://github.com/aleclarson/vite-tsconfig-paths/compare/master...fwouts:lazy

This seems to be working (shaving off 20 seconds of unnecessary work in my case) but is completely missing the project references priority handling mentioned above, since I don't understand how that's supposed to work :)

It also assumes one directory = one project but the current implementation seems to support more than one resolver per directory? I'd love some more context here. Thanks!

Feel free to take over the code and implement it your way too, I don't care about attribution.

fwouts commented 3 months ago

I would love to know your thoughts on this, thanks!