Documentation
¶
Overview ¶
Package spa provides a unified SPA (Single-Page Application) loader for wick's Vite-built Svelte frontends. It handles:
FS selection — compile-time embed.FS in production; os.DirFS when WICK_DEV_REPO_ROOT is set so Vite watch rebuilds are served without recompiling Go.
Asset URL resolution — reads the hashed bundle src from each app's index.html (multi-app: one dist/ root holds dist/<app>/index.html). Cached per-app in production; re-read on every call in live-disk mode.
Dev reload — a single global SSE endpoint (/_dev/reload) that watches all registered dist/ directories and broadcasts a "reload" event to every connected browser tab whenever any bundle rebuilds. Only active when WICK_DEV_REPO_ROOT is set. Call RegisterGlobalHandler(mux) once in the root server; ui.Layout injects DevReloadScript() unconditionally (returns "" in production).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DevReloadScript ¶
func DevReloadScript() string
DevReloadScript returns the inline <script> tag that connects to /_dev/reload and auto-reloads the page on each build. Returns "" when WICK_DEV_REPO_ROOT is not set (production). Safe to inject unconditionally.
func RegisterGlobalHandler ¶
RegisterGlobalHandler registers GET /_dev/reload on mux only when WICK_DEV_REPO_ROOT is set. No-op otherwise — call unconditionally in server.
Types ¶
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader is the live-disk-aware SPA filesystem + asset-URL resolver for one dist/ root. A root holds one or more apps at dist/<app>/. Create with New.
func New ¶
New creates a Loader for a single dist/ root and auto-registers it in the global dev-reload registry when WICK_DEV_REPO_ROOT is set.
- embedded: compile-time embed.FS (must contain dist/...)
- repoRelDir: repo-root-relative path to the dir holding dist/, e.g. "internal/manager" or "internal/tools/agents"
When WICK_DEV_REPO_ROOT is set and dist/ exists on disk, the loader switches to os.DirFS so Vite watch rebuilds surface without a Go recompile.
func (*Loader) AssetURL ¶
AssetURL returns the absolute URL of the hashed entry .js bundle for app, read from dist/<app>/index.html. fallbackBase is the URL prefix used to build the asset URL when index.html has no script tag (rare: a hand-rolled dist tree) — e.g. "/manager/_app/assets". Returns "" when not built yet.
Cached per-app in production; re-read on every call in live-disk mode so a Vite rebuild's new hash surfaces on the next render.
func (*Loader) FS ¶
FS returns the active filesystem (embed or live-disk), rooted so that dist/<app>/... paths resolve.
func (*Loader) IsLiveDisk ¶
IsLiveDisk reports whether live-disk mode is active.