AsterDocsv1.2.3

Docs / Guides

Getting started

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:

bash
# macOS / Linux
curl -fsSL https://vite.plus | bash

# Windows (PowerShell)
irm https://vite.plus/ps1 | iex

2. Create and run an app

bash
vp dlx @fierst/aster@1.2.3 my-app
cd my-app
npm install --save-exact @fierst/aster@1.2.3
vp dev

The 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.

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:

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:

tsx
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.

tsx
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.