Multiple JSX Runtimes #86
-
I have a large game engine project that uses multiple JSX runtimes. The "editor" component uses React, while the "game" component uses a custom JSX factory that creates a tree of game objects. (The game itself, without the editor, doesn't depend on React but it does use JSX.) Currently the way I am handling this is:
This strategy doesn't work with the new plugin. I've tried playing with both tsconfig and the @jsx pragma, and it appears to always use the React "automatic" runtime no matter what I do. However, what I'd really like is to be able to compile everything in a single Vite build - this would mean either having to put jsx pragmas in every file, or (better) being able to set the runtime on a per-directory basis, using include/exclude patterns in vite.config.js. (Note that, according to the docs, the "include" option on the jsx plugin only controls which modules are hot reloaded, not which modules are transformed.) I can "kind of" make things work by precompiling the game using tsc, but this means I lose all hot reloading and other nice DX of Vite. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I think this use case never come up before but it should be possible to handle it in the future for TS now that jsx transformation is done via esbuild because the esbuild plugin correctly resolve options for nested tsconfig. The issue is that the options for jsx runtime is overridden for all files here: https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L136-L156 You can try to patch it and remove these lines. I will see if I can simplify this in the next major version |
Beta Was this translation helpful? Give feedback.
-
Oh ok so this is because of https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L443 But this still not solved your problem because since v3 we tell Babel to output jsx and let esbuild to jsx -> js: vitejs/vite#9590 |
Beta Was this translation helpful? Give feedback.
I think this use case never come up before but it should be possible to handle it in the future for TS now that jsx transformation is done via esbuild because the esbuild plugin correctly resolve options for nested tsconfig. The issue is that the options for jsx runtime is overridden for all files here: https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L136-L156
You can try to patch it and remove these lines. I will see if I can simplify this in the next major version