Aster 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. Install Vite+ (vp)
If you don't already have Vite+ installed globally:
# macOS / Linux
curl -fsSL https://vite.plus | bash
# Windows (PowerShell)
irm https://vite.plus/ps1 | iex2. Create and run an app
vp dlx @fierst/aster@1.2.3 my-app
cd my-app
npm install --save-exact @fierst/aster@1.2.3
vp devThe CLI names are aster and create-aster. The default target is my-aster-app. Use an empty directory. The optional --force flag overwrites matching starter files in an existing directory. The scaffold declares a compatible version range. The install command above locks the app to the version used on this site.
Open the URL printed by vp dev. Edit src/main.tsx, then click the button from src/counter.tsx to see local state persist. To add an optional AsterUI button, run npx @fierst/ui@1.0.2 add button, install the dependencies printed by the CLI and import Button from ./ui/button. Run vp build to create the static client site in dist/ and vp preview to try it locally. Configure your static host to serve index.html for client routes.
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 Aster to an existing Vite+ app
Install @fierst/aster in the app (for example, npm install --save-exact @fierst/aster@1.2.3). Add aster() from @fierst/aster/vite to your vite.config.ts:
import { defineConfig } from 'vite-plus';
import aster from '@fierst/aster/vite';
export default defineConfig({
plugins: [aster()],
});Set "jsx": "react-jsx" and "jsxImportSource": "@fierst/aster" in tsconfig.json, and write standard .tsx components:
import { render } from '@fierst/aster';
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. Aster 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/aster-manifest.json' with { type: 'json' };
import { htmlResponse } from '@fierst/aster/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/aster-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.