S
SolidJS16mo ago
walid

SWC Support for SolidJS

Reading vitejs's docs, I've came across SWC and I'm wondering if this could be achievable using this: https://github.com/modderme123/swc-plugin-jsx-dom-expressions I also stumbled upon a github feed discussion where they stated that SSR and refs are not supported, please let me know 🙏
14 Replies
Alex Lohr
Alex Lohr16mo ago
The problem is that DOM expressions are a moving target, so any implementation would either have to utilize the original babel plugin or follow the official version closely. That's also the reason native solid compilation in bun was never finished.
walid
walidOP16mo ago
So, currently developers are struggling tracing reactive components inside the DOM to make it work with SWC ?
Tommypop
Tommypop16mo ago
Hi, the SWC plugin is fairly complete and it can compile both the playground and the main site without issues I'm not entirely sure about refs support (I haven't tested it yet and haven't worked on that part of the plugin) And, yeah, neither SSR nor hydration work yet
Tommypop
Tommypop16mo ago
Here's a config with the plugin set up (it's also got windi in it)
walid
walidOP16mo ago
Glad to hear that, thanks for letting me know. tysm 💖
Tommypop
Tommypop16mo ago
You're welcome :) Feel free to report any issues you encounter
Kevin.
Kevin.2mo ago
Hey @Tommypop, Is this plugin production ready with SSR support and hydration working ? I'm currently creating a css in js library for solid.js / solidStart using SWC for the jsx transformation in a custom vite plugin and ran into the problem of finding out no support for solid.js
Tommypop
Tommypop2mo ago
It's definitely not production ready and, afaik, there's no SSR or hydration support yet
nuno
nuno2w ago
I see a good use of this on other bundler that can use SWC, like webpack or RsPack. I tried to use the same config with RsPack but seems like I am mssing something I get this error HarmonyLinkingWarning: export 'jsxDEV' (imported as '_jsxDEV') was not found in 'solid-js/jsx-dev-runtime'
Nuno
Nuno2w ago
I fixed this by setting importSource = "solid-js/h" but now I have a issue with context seems like context provider is not working well, I get null trying to get the created context on useContext
Alex Lohr
Alex Lohr2w ago
That is due to solid-js/h supports react-style JSX transforms, but does not create the reactive effects for props changes, so you need to do them manually. And context will also not work.
Nuno
Nuno4d ago
Ok. So a bit incomplete. But I my option we may need something like this. I had to revert vite to webpack due some production build inconsistencies. Solid relies to much on vite, but I think we need other tools and ways of work that doesn't demand use vite. Babel and a Webpack are slow and other build tools are promising better performance. I think SWC still need to do something to allow write plugins without know Rust, I found the code hard to read.
Alex Lohr
Alex Lohr3d ago
I think the solution will be something like using porffor to transpile plugin transformers into wasm to run them in a performant way directly from the rust code.
Alex Lohr
Alex Lohr3d ago
Maybe such a solution will be part of https://oxc.rs/ at some point.
Oxc
The JavaScript Oxidation Compiler
A collection of high-performance JavaScript tools written in Rust
Want results from more Discord servers?
Add your server