aleclarson / vite-tsconfig-paths

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

Unable to use this plugin from custom extensions (like .vue) #25

Closed TrixterTheTux closed 3 years ago

TrixterTheTux commented 3 years ago

Seems that it is impossible to allow inclusions from specific file extensions (e.g. .vue) with the tsconfig's included parameter due to the following line here as it converts any custom extension glob into a one that will always match directories only, e.g. ./src/**/*.vue will convert to ./src/**/*.vue/**

Version: 3.3.10 (previously tested 3.2.1 where it worked as intended) The plugin is initialized like this:

tsconfigPaths({
    extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.vue'],
})
aleclarson commented 3 years ago

Thanks for investigating.

Here's my proposed solution:

-  if (!glob.endsWith('*') && !/\.[tj]sx?/.test(glob)) {
+  if (!glob.split('/').pop().includes('*')) {

Basically, if the last path component is not a glob, append /**.

Can you open a PR with that change? ^^

TrixterTheTux commented 3 years ago

Done, https://github.com/aleclarson/vite-tsconfig-paths/pull/26