aleclarson / vite-tsconfig-paths

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

feat: add `loose` option #10

Closed lanthaler closed 3 years ago

lanthaler commented 3 years ago

I spent quite a while wondering why my tsconfig paths didn't work in .vue SFC files till I found this code which ignores all the config for all files but TS/JS source files. This option addresses it by applying the paths globally just as setting them up in resolve.alias in vite.config.ts would.

aleclarson commented 3 years ago

What version of Vite are you using?

Last I checked, this plugin works fine with .vue SFC files. See the demo branch.

lanthaler commented 3 years ago

I tested it with Vite 2.0.4. It doesn't work when I use aliases in the template part of a SFC. I get errors such as

 [vite] Internal server error: Failed to resolve import "@assets/symbols.svg". Does the file exist?
aleclarson commented 3 years ago

I'm not familiar with Vue. Can you fork the demo branch, reproduce the issue, and share it here so I can debug it?

lanthaler commented 3 years ago

Here are the necessary changes to reproduce the issue on the vue demo branch: https://github.com/lanthaler/vite-tsconfig-paths/commit/3d260254bfa3824eda1c53df97cee7821c786b22

dipasqualew commented 3 years ago

I am experiencing the same problem:

typescript: 4.1.3 vite: 2.0.5

 > src/main.ts:5:16: error: No loader is configured for ".vue" files: src/App.vue
    5 │ import App from '~/App.vue';
aleclarson commented 3 years ago

@dipasqualew That seems unrelated. Open a new issue with a repro, thanks!

aleclarson commented 3 years ago

@lanthaler Ah ok, that's not within a <script lang="ts"> block, so it's unsupported. But it's a good argument for merging this PR. :)

aleclarson commented 3 years ago

Released in v2.5.0