API reference
v0.0.1 โ minimal surface. Three exports. That's the API.
svelteRenderer(component, options)
Returns a Hono MiddlewareHandler that responds with an HTML document containing the SSR'd Svelte component, followed by a hydration script that mounts the matching client bundle.
| Option | Type | Required | Notes |
|---|---|---|---|
hydrateAs | string | yes | Matches a key in the bundles map passed to attachSvelteRoutes. |
props | Record<string, unknown> | no | Same props used by SSR and hydration. JSON-serialized into the page. |
title | string | no | Sets <title>. |
head | string | no | Extra raw <head> HTML. |
bodyClass | string | no | Class on the <body>. |
attachSvelteRoutes(app, options)
Registers GET /__svelte/:id.{js,css} routes on the Hono app. Call once per app instance. Idempotent.
| Option | Type | Notes |
|---|---|---|
bundles | Record<string, { js, css }> | Keyed by hydrateAs. The build helper produces this. |
prefix | string | Defaults to "/__svelte". Override only on collision. |
buildHonoSvelte(options)
From hono-svelte/build. Two esbuild passes โ client + server โ emitting a single bundled worker with all client bundles inlined as build-time string constants.
| Option | Type | Notes |
|---|---|---|
workerEntry | string | Path to your Worker entry (TS or JS). |
outDir | string | Output dir. worker.bundled.mjs lands here. |
components | Record<string, string> | id โ path to .svelte file. id matches hydrateAs. |
target | string | Defaults "es2022". |
dev | boolean | Source maps + no minify. Defaults false. |
The constant the build injects
Inside your worker source:
declare const __HONO_SVELTE_BUNDLES__: Record<string, { js: string; css: string }>; esbuild's define replaces this identifier with a JSON object at build time. Pass it directly to attachSvelteRoutes.
Constraints
- Build-time compile. No
evalat runtime โ Workers prohibits it. See Why. - One root per page. SSR mount target is
#hono-svelte-root. - Non-streaming HTML. Full document in one Response. Workers fan out at the edge; streaming is rarely the right primitive at this size.
- Hono owns routing. No file-system router, no
loadfunctions, no+layout.svelte. Use Hono. That's the point.