Open-source compiler · Rust + WebAssembly
Zubra
A compiler for Web Components: write a component as HTML with bindings and a script, and get server-rendered HTML plus a small custom element that hydrates it.
My role: Creator · Maintainer
Open the playground to edit a component and watch it compile in your browser, or browse the example apps.
The problem
Custom elements work in every framework, but writing them by hand means boilerplate, and rendering them on the server is left to you. Framework components are easier to write, then only work inside that framework.
The solution
A Zubra component is one .zb file: a script, scoped styles, and a template with {expr} bindings. The compiler turns it into HTML the server can send and a small custom element that hydrates that HTML. React, Vue, Svelte, and plain pages use the element without integration code, and zubra compile prints the generated HTML and JavaScript so the output can be read.
My contributions
- Wrote the compiler in Rust as a command-line tool and a WebAssembly build, so the same compiler runs in a terminal, in bundlers, and in the browser playground.
- Designed server rendering that works with JavaScript off, with hydration that binds to the existing DOM instead of replacing it.
- Published bundler plugins for Vite, Rollup, webpack, esbuild, and Rspack, plus packages for server rendering in Express, Fastify, and Hono, form-post server functions, and on-device state that syncs across tabs and devices.
- Built a playground that compiles in the browser and runs one component in plain HTML, React, and Vue side by side, and a gallery of 28 complete example apps.
- Wrote the guide, reference, and migration notes, and a starter (npm create zubra) with a template per framework.
Behind the project
I wanted components I could write once and use in plain HTML, in any framework, and on the server. Zubra is now on a 6.x long-term-support line, and I test it by building real products on it: the Zubra UI component library, the open.parlor games site, and open.blog's Studio.
Engineering decisions
A compiler's output becomes other people's dependency, so changing it breaks their apps. Version 6.0 starts a long-term-support line: the .zb format, the compiled output's interface, the command-line tool, and the typings are frozen until 7.0. The cost is that improvements needing a format change have to wait for a major version.
Testing
The repository runs Rust tests for the compiler, runtime unit tests, Chromium tests for hydration, slots, events, and memory leaks, and plugin tests against real React, Vue, Svelte, Solid, Lit, and Astro apps. The changelog records fixes from repeated security audits. I built the compiler and site from source and ran the playground locally to capture these screens.
- Repository
- zubra-js/zubra
- Repository updated