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

Vite Support #107

Open
brillout opened this issue Jul 22, 2021 · 13 comments
Open

Vite Support #107

brillout opened this issue Jul 22, 2021 · 13 comments

Comments

@brillout
Copy link

I supporting https://vitejs.dev something you're interested in?

So that users can simply:

// vite.config.js

import { typescriptIs } from 'typescript-is/vite-plugin'

export default {
  plugins: [typescriptIs]
}
@lukasluecke
Copy link

@brillout I know it's been a while since you made this comment, but I would love something like this. How would you go about implementing that? Any pointers?

@Fuzzyma
Copy link

Fuzzyma commented Feb 17, 2022

Vite uses esbuild to prebundle dependencies and to transpire code on the fly in dev mode. Esbuild does not parse type information. Therefore typescript-is can't work there. You would need to replace esbuild with typescript which will hugely slow down dev experience

@lukasluecke
Copy link

I was assuming that @brillout had some solution in mind when proposing this.

I'm currently comparing a bunch of libraries for this, some using babel macros, some based on typescript, etc. - just trying to find out how each of them could be integrated in a Vite project 🙂 I would actually be fine with having generating the typeguards be a separate process as well, so might look into how that would work.

@Fuzzyma
Copy link

Fuzzyma commented Feb 17, 2022

I think there is a competitor to this lib that is doing it as build process. It has its own gotchas but it would work I guess.

Also: the rust compiler swc does parse types and is probably as fast as esbuild. Writing a plug in for swc might work. Evan himself gave that advice when I asked him about that :)

@brillout
Copy link
Author

@lukasluecke What's your use case?

@Fuzzyma A strategy is to apply typescript-is's transfomer only for a couple of files, then performance is not an issue. For example only for .telefunc.js files (when using Telefunc).

In general, if it works for webpack, I don't see any reason why it wouldn't work for Vite.

@lukasluecke
Copy link

@Fuzzyma Do you know which competitor that is by any chance? Might be another one to add to my list of candidates 😁

Yeah I'm not really looking to switch to swc at the moment, at least not for just this.

@lukasluecke
Copy link

@brillout Yeah that was one of my ideas as well, but I'm not sure if it needs to "transform" all files that contain types referenced in the guard - or if it is able to traverse them automatically.

Use case is basically validating some JSON loaded externally against MUI theme schema (and some custom types). Would love to have it based on the types, instead of something like JSON schema.

@Fuzzyma
Copy link

Fuzzyma commented Feb 17, 2022

Lib: https://github.com/rhys-vdw/ts-auto-guard

Ofc webpack can do it. So can roll up. They both use typescript under the hood to accomplish that. But as esbuild made painfully clear: build tools ate awfully slow and you don't really want typescript in your build chain. However, a watcher process that would only compile those files on change might work because that change would be picked up by vite and trigger a reload or hmr

@lukasluecke
Copy link

@Fuzzyma Thank you!

@brillout
Copy link
Author

@lukasluecke Exhaustive list: https://github.com/akutruff/typescript-needs-types. Let me know if you find something suitable for Vite.

@Fuzzyma You may want to use esbuild for node_modules but for user code using a slower transpiler is not a problem since Vite transpiles in a lazy fashion.

@Fuzzyma
Copy link

Fuzzyma commented Feb 17, 2022

@brillout i am sure you would totally feel the difference. There is a reason why vite is a bliss to use. But ofc there is no other reason not to do it

@yinzixie
Copy link

Any upgrade? Or anyone can teach me how to setup it with vite?

@samchon
Copy link
Contributor

samchon commented Oct 10, 2022

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

No branches or pull requests

5 participants