-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
JSX Transform Support in Vite without using pragma #2523
Comments
AFAIK there is no transform plugin system in Vite since it's esbuild-based. So I'm unsure how we could support this easily without incurring significant performance costs related to transformations. Maybe you could hack around a transformation like this: transform(code) {
return { code: `/** @jsx __EmotionJSX */\nimport { jsx as __EmotionJSX } from '@emotion/react'\n${code}` }
} I leave it to you to figure out how to plug this into Vite though, this simple version would also probably mess up source maps. Note that this could be supported out of the box by esbuild but the author doesn't seem to be interested in supporting the modern, official, JSX transform. Related issues: I'm just not familiar with Vite to prepare this myself, if you'd like to contribute it - I'm open to accepting a PR for this. |
Just a heads up that the first party @vite/plugin-react does use babel. Preconfigured to support the Not sure about how this affects performance, but source maps are all good. |
Seems like your options are:
While I don't think there are any code changes we can make to improve this situation, I can add a blurb about this to our documentation site. |
I made a plugin for esbuild which may solve this issue for you. It works by substituting the https://www.npmjs.com/package/esbuild-plugin-jsximportsource |
For anyone coming to this thread now, this is officially supported in esbuild now: https://github.com/evanw/esbuild/releases/tag/v0.14.51 |
The problem
The use of babel in vite is an anti-pattern as it apparently brings "major performance hits". See vitejs/vite#1742 for more.
However, according to the docs the only alternative to using babel is to use the pragma, which is quite inconvenient in terms of the boilerplate it adds for each usage.
Proposed solution
To add some sort of transformative support for vite similar to what babel does
The text was updated successfully, but these errors were encountered: