Vite
Requires Vite 8 or newer. The plugin calls Vite’s own transformWithOxc,
which Vite 6 and 7 do not export – on those the build fails at config load
with does not provide an export named 'transformWithOxc', naming neither
Vite nor its version.
These steps start from Vite’s React starter
(npm create vite@latest my-app -- --template react-ts) and are built in CI
exactly as written here, from packed packages.
To see the result before setting anything up,
open the finished project in StackBlitz.
It runs in the browser, on the WebAssembly build of the compiler, which
StackBlitz needs because it cannot load a native addon; compiles there are
about half as fast as on your machine. The same project is
on GitHub to
copy with npx degit iray-tno/hozo/templates/vite my-app.
npm install --save-dev @hozo/vite @hozo/compilernpm install @hozo/coreimport { hozo } from '@hozo/vite'import react from '@vitejs/plugin-react'import { defineConfig } from 'vite'export default defineConfig({ // `hozo()` before `react()`: it has to see the original JSX, before // the React plugin's transform touches the file. plugins: [hozo({ css: 'src/theme.css' }), react()],})css names the stylesheet that holds your design tokens. Hozo reads it; it
does not have to be imported anywhere. Keep the option even though Hozo has
a default list: the starter’s src/index.css is on that list, and it is
plain CSS with no @import "tailwindcss", so without css Hozo would read
it and compile against Tailwind’s defaults. The stylesheet itself:
@import "tailwindcss";@theme { --color-brand: oklch(62% 0.19 258);}Your first component
Section titled “Your first component”Write components with Hozo’s primitives and Tailwind classes. The build turns them into HTML elements and a stylesheet:
import { Button, Heading, View } from '@hozo/core'import { useState } from 'react'export default function App() { const [count, setCount] = useState(0) return ( <View className="gap-4 p-8"> <Heading level={1} className="text-3xl font-bold text-brand"> Hello, Hozo </Heading> <Button className="self-start rounded-lg bg-brand px-4 py-2 text-white" onPress={() => setCount(count + 1)} > Pressed {count} times </Button> </View> )}Run npm run dev. The heading is an <h1>, the button a <button>, and
their classes are plain CSS.