Blokd pairs a browser-native generator runtime with Vite+ for development, testing, type checking and production builds. Use Node 20.19 or later for the package.
1. Create and run an app
Use Node.js 20.19 or later. The starter declares Vite+ as a development dependency. Installing the app’s dependencies gives its npm scripts access to the project’s own version of Vite+.
npx blokd my-app --install
cd my-app
npm run devOpen the local URL printed by the dev server. Edit src/main.tsx, then try the counter in src/counter.tsx. Run npm run build to write a production build to dist/, and npm run preview to serve that build locally.
The optional --install flag (short form -i) runs npm install inside the new app. Omit it to scaffold only. If installation fails, run npm install in the generated directory to retry. Run npx blokd --help for scaffold options. With no directory argument, the launcher creates my-blokd-app. Use an empty directory unless you intend to overwrite matching starter files with --force.
2. Add a UI component
From the new app’s directory, run:
npx blokd-ui add button
npm install @lucide/iconsImport Button from ./ui/button in src/main.tsx. The installer copies the source and its theme and icon helpers into src/ui. Run npx blokd-ui list to browse other components.
Local state
Print one sheet. Both totals change, but the component keeps just one number in memory.
import "./example.css";
export default function* PrintRun() {
let sheets = 0;
for (;;) {
const invitations = sheets * 2;
yield (
<section class="specimen press">
<header>
<h1>Letterpress run</h1>
<span>2 invitations per sheet</span>
</header>
<div class="readouts">
<div>
<output>{sheets}</output>
<span>Sheets printed</span>
</div>
<div>
<output>{invitations}</output>
<span>Invitations ready</span>
</div>
</div>
<footer>
<button class="primary" onClick={() => sheets++}>
Print a sheet
</button>
<button disabled={!sheets} onClick={() => (sheets = 0)}>
Reset press
</button>
</footer>
</section>
);
}
}
@media screen and (prefers-reduced-motion: no-preference) {
#example button.btn:enabled {
transition: transform 120ms ease-out;
}
#example button.btn:enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button.btn:enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
color-scheme: light dark;
--control-border: light-dark(#827a87, #928699);
--accent: light-dark(
oklch(0.45 var(--site-chroma, 0.15) var(--site-hue, 296)),
oklch(0.8 calc(var(--site-chroma, 0.15) * 0.74) var(--site-hue, 296))
);
--on-accent: light-dark(white, #18131e);
--ink: light-dark(#2b2630, #f4edf7);
--quiet: light-dark(#645d69, #c8bdcd);
--edge: light-dark(#d9d1df, #514857);
--paper: light-dark(#fffdfa, #27232c);
--canvas: light-dark(#f1edf2, #201c24);
font:
1rem/1.5 system-ui,
sans-serif;
}
:root[data-site-theme="light"] {
color-scheme: light;
}
:root[data-site-theme="dark"] {
color-scheme: dark;
}
body {
margin: 0;
padding: clamp(0.85rem, 4vw, 1.7rem);
color: var(--ink);
background-color: var(--canvas);
background-image: radial-gradient(var(--edge) 0.8px, transparent 0.8px);
background-size: 13px 13px;
}
.specimen {
max-width: 38rem;
margin: auto;
padding: clamp(1rem, 4vw, 1.65rem);
border: 1px solid var(--edge);
border-top: 3px solid var(--accent);
border-radius: 0.7rem;
background: var(--paper);
box-shadow: 0 4px 12px #211a2810;
}
.specimen header,
.specimen footer,
.demo-box,
.demo-row,
.demo-confirm {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.65rem;
}
.specimen header {
justify-content: space-between;
gap: 0.4rem;
margin-bottom: 0.9rem;
}
h1,
h3 {
margin: 0;
font-size: 1.25rem;
line-height: 1.2;
letter-spacing: -0.035em;
}
header > span,
.caption,
.readouts span,
dt {
font:
500 0.78rem/1.4 ui-monospace,
Consolas,
monospace;
color: var(--quiet);
}
p {
margin: 0.6rem 0 1rem;
}
.specimen footer {
margin-top: 1rem;
}
button,
input,
select {
font: inherit;
color: var(--ink);
border: 1px solid var(--control-border);
border-radius: 0.45rem;
padding: 0.45rem 0.72rem;
max-width: 100%;
background: var(--paper);
}
button {
cursor: pointer;
font-weight: 570;
}
button:hover {
border-color: var(--accent);
}
button:disabled {
opacity: 0.55;
cursor: default;
}
.primary {
color: var(--on-accent);
background: var(--accent);
border-color: var(--accent);
}
.danger {
color: light-dark(#913148, #ffb5c2);
background: light-dark(#fff3f4, #3c2930);
}
:focus-visible {
outline: 3px solid var(--accent);
outline-offset: 2px;
}
.readouts,
.route-result {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 0.65rem;
margin: 0.6rem 0;
}
.readouts > div,
.route-result > div {
display: grid;
gap: 0.15rem;
padding: 0.65rem 0.85rem;
background: var(--canvas);
border-radius: 0.35rem;
}
.readouts output,
.ticket-body output {
font:
600 2.55rem/1.1 ui-monospace,
monospace;
letter-spacing: -0.08em;
color: var(--accent);
}
dd {
margin: 0;
font:
600 0.92rem/1.4 ui-monospace,
monospace;
}
.field {
display: grid;
gap: 0.22rem;
margin: 0.5rem 0;
color: var(--quiet);
font-weight: 550;
}
.field input {
width: 100%;
}
.score-controls {
align-items: flex-end;
}
.score-controls .field {
margin: 0;
}
.demo-list {
list-style: none;
margin: 0.6rem 0 0;
padding: 0;
}
.demo-list li {
border-top: 1px solid var(--edge);
padding: 0.37rem 0;
}
.checklist form,
.specimen > .demo-box {
margin: 0.5rem 0;
}
.pill,
.notice {
padding: 0.25rem 0.6rem;
color: var(--accent);
background: var(--canvas);
border-radius: 0.4rem;
}
.done {
text-decoration: line-through;
color: var(--quiet);
}
.demo-muted {
color: var(--quiet);
}
.trace-log {
max-height: 11rem;
overflow: auto;
padding: 0.7rem 0.8rem 0.7rem 2.7rem;
margin: 0.6rem 0 0;
background: light-dark(#322b38, #151119);
color: #f3e9fc;
font:
0.83rem/1.65 ui-monospace,
monospace;
border-radius: 0.45rem;
}
.trace-log li::marker {
color: #c6a3e5;
}
.trace button {
margin: 0.15rem;
}
.ticket-body {
display: flex;
align-items: center;
justify-content: space-between;
border-block: 1px dashed var(--edge);
padding: 0.65rem 0;
}
.ticket-body output {
display: block;
}
.perforations {
height: 2.3rem;
width: 5rem;
background: repeating-linear-gradient(
90deg,
var(--accent) 0 2px,
transparent 2px 4px,
var(--accent) 4px 5px,
transparent 5px 8px
);
}
3. Follow a change through the component
Open the local state example. Click the button twice, then reset it. In the source, find the initial count before the loop and the derived value inside it. Move the initial count into the loop in your scaffold and see what happens on the second click. Moving it back restores the counter.
When an app needs to share the count between components, use a signal. Explore shared state and changing props.
4. Add Blokd to an existing Vite+ app
Install @fierst/blokd in the app (for example, npm install --save-exact @fierst/blokd@1.2.3). Add blokd() from @fierst/blokd/vite to your vite.config.ts:
import { defineConfig } from 'vite-plus';
import blokd from '@fierst/blokd/vite';
export default defineConfig({
plugins: [blokd()],
});Set "jsx": "react-jsx" and "jsxImportSource": "@fierst/blokd" in tsconfig.json, and write standard .tsx components:
import { render } from '@fierst/blokd';
export function* Counter() {
let count = 0;
for (;;) {
yield <button onClick={() => count++}>Clicks: {count}</button>;
}
}
render(<Counter />, document.getElementById('app')!);The Vite plugin parses JSX and TSX with Oxc before Vite strips TypeScript. Blokd lowers JSX into hoisted template slots, maps expressions back to their original positions, and stamps exported generator components for lazy revival. The Astro integration uses the same compiler.
5. Return HTML from a Fetch handler
Use a TSX server entry in a Fetch-based host. Build and serve the client assets first, then import that build's manifest in your server bundle.
import manifest from '../dist/blokd-manifest.json' with { type: 'json' };
import { htmlResponse } from '@fierst/blokd/ssr';
import { App } from './app.tsx';
export default {
fetch(req: Request) {
const url = new URL(req.url);
return htmlResponse(<App url={url.pathname + url.search} />, {
title: 'My App',
revive: true,
manifest,
});
},
};For a split client/server build, keep browser-safe components in shared modules. Import the island modules from the client entry (a side-effect import such as import './Counter.tsx' lets the plugin discover its exports). Run vp build for the client, then vp build --ssr src/server.tsx --outDir dist-server for a server entry at that path. Resolve the manifest import relative to the entry file, for example ../dist/blokd-manifest.json from src/server.tsx. Serve the contents of dist/ at the configured public base. Route document requests to your Fetch handler and asset requests to the client files. The handler above is a Fetch-host module, so a Node HTTP server needs its own Request/Response adapter.