aleclarson / vite-tsconfig-paths

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

Doesn't work with Svelte #11

Closed V-ed closed 3 years ago

V-ed commented 3 years ago

This plugin doesn't seem to work with Svelte files.

I can see in this issue that the goal would be to only apply this script to .vue modules :

@scambier See #4. The path mapping should only apply to lang="ts" scripts in .vue modules, but it's not implemented yet.

With Vite 2 becoming framework agnostic, I was wondering if this stance will still be kept? Or am I missing something in my config? I'd like to use this for automatic path mapping, it's really useful!

Thanks in advance!

aleclarson commented 3 years ago

If you fork this repo and update the ./demo directory to use Svelte, I will debug it. 👍

V-ed commented 3 years ago

There you go! https://github.com/V-ed/vite-tsconfig-paths

(I used npm, just fyi since I believe you are using yarn)

Simply comment out the lines : https://github.com/V-ed/vite-tsconfig-paths/blob/e1770b7aaf140533a274845ce36e7661f57510a0/demo/vite.config.ts#L7-L12 (the resolve.alias object) to verify if tsconfigPath() works or not.

aleclarson commented 3 years ago

Supported in v2.4.0

V-ed commented 3 years ago

Awesome, thanks @naranjamecanica and @aleclarson !

V-ed commented 3 years ago

Well, it works in my reproduction repo but not in my current app haha, I'll debug some more, might be due to other plugins, I'll keep this thread updated with what I find!

aleclarson commented 3 years ago

Make sure you have checkJs: true in your tsconfig

V-ed commented 3 years ago

Make sure you have checkJs: true in your tsconfig

That was exactly it. I even checked the PR's code and saw the checkJs config option conditional, yet still didn't think about it.

This should probably be mentioned in the README, especially for those using typescript in files other than tsx? - checkJs is not often setup in my repos haha.

Thanks for the quick tip have have a nice day!