Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for specified tsconfig file #10531

Open
4 tasks done
ylc395 opened this issue Oct 19, 2022 · 5 comments
Open
4 tasks done

Add support for specified tsconfig file #10531

ylc395 opened this issue Oct 19, 2022 · 5 comments

Comments

@ylc395
Copy link

ylc395 commented Oct 19, 2022

Description

There is no way to specify a tsconfig file for vite now.

See related Discussions:

#8483
#4333
#3939

Suggested solution

Provide a field named tsconfig in esbuild field of vite config.

Basically, we can pass this field to here:

const loadedTsconfig = await loadTsconfigJsonForFile(filename)

Alternative

No response

Additional context

I'm glad to implement this feature.

Validations

@sapphi-red
Copy link
Member

I think there's already tsconfigRaw property.
https://stackblitz.com/edit/vitejs-vite-in7pn4?file=vite.config.js&terminal=dev

@ylc395
Copy link
Author

ylc395 commented Oct 20, 2022

Yes. But what if we prefer config file, especially using extends?

@sapphi-red
Copy link
Member

sapphi-red commented Oct 20, 2022

In that case, using tsconfck will work as a workaround.

@EdieLemoine
Copy link

I made another workaround, a small Vite plugin that copies your other tsconfig to tsconfig.json before the build, and removes it after. It's vite-plugin-custom-tsconfig

@ghost
Copy link

ghost commented Jun 16, 2023

I'd like to specify the tsconfig.json file vite should use (and I also expect it to be watched for changes).

We have 2 files:

  1. tsconfig.build.json which is used for creating builds with lax error checking.
  2. tsconfig.json which is used by IDEs (some of which we can't configure, which is another problem) and default for some tools; it has strict error checking (vite shows errors with this, because our codebase is not ready for strict checking yet.. which is why we want warnings in our IDEs, but not during builds).

I think there's already tsconfigRaw property. https://stackblitz.com/edit/vitejs-vite-in7pn4?file=vite.config.js&terminal=dev

I'm using this workaround right now.
However, it does feel very hacky.

For example, changes to tsconfig.json will not trigger a rebuild (although to be fair, this is complicated further by tsconfig.json "extends" option etc.).

In that case, using tsconfck will work as a workaround.

Even after reading the tsconfck README, I'm not sure how to do this?

I made another workaround, a small Vite plugin that copies your other tsconfig to tsconfig.json before the build, and removes it after. It's vite-plugin-custom-tsconfig

This seems very dangerous, I'd imagine this could break in a number of scenarios.


I feel it is the responsibility of vite to load (and watch) tsconfig from a specified path and passing it to esbuild in tsconfigRaw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants