aleclarson / vite-tsconfig-paths

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

Feature request: Specify the path to the `tsconfig` #3

Closed cawa-93 closed 3 years ago

cawa-93 commented 3 years ago

I'm working on template for creating electron applications. In src are several entry points. Each has its own tsconfig and vite.config. And no tsconfig is at the root of the project.

aleclarson commented 3 years ago

In vite@2, Rollup plugins are valid Vite plugins, so you could try one of them if you'd like: https://www.npmjs.com/search?q=rollup%20typescript%20paths

Otherwise, PR welcome!

aleclarson commented 3 years ago

I'm working on upgrading vite-tsconfig-paths to work with vite@2, since none of the Rollup plugins use the tsconfig-paths package like I do. I'm planning on using the root option from vite.config.js as the directory to search for tsconfig.json. Will that work for your use case?

cawa-93 commented 3 years ago

Nope. In my case, there are several entry points, they have their own tsconfig and they are all deeper than the root.

aleclarson commented 3 years ago

@cawa-93 Ah ok. You said they each have their own vite.config.js, but I suppose the root is still defaulting to process.cwd() for each of them.

If you install vite-tsconfig-paths@next and vite@next, you can do this:

import tsconfigPaths from 'vite-tsconfig-paths'

export default {
  plugins: [
    tsconfigPaths({ root: __dirname }),
  ]
}