Skip to content

API

ogygia/vite

The Vite plugin and its configuration options.

On this page

This page is generated from the package’s own .d.ts files on every build, so the signatures, descriptions and examples below always match the source.

Exports definePlugin · import_keys_hint · islandChunkFileName · islandId · islandPublicUrl · normalize_import_keys · ogygia · regionId · regionIdentity · rewrite_lake_import_to_placeholder · strategyKey · wrapperVirtualId · CLIENT_BINDING_STUB · DEFAULT_IMPORT_KEYS · MARKDOWN_EXTENSION_API · BuildContext · ExportMap · ExportsSeam · MacroContext · MarkdownExtension · MarkdownFinish · MarkupRegions · MarkupSource · OgygiaOptions · OgygiaPlugin · OgygiaPreset · OgygiaRateLimit · PageReads · PageReadWhy · PinnedDecl · PluginDefinition · Policy · PrescanHook · RegionsSeam · StageTransform · TransformContext · Entry · ImportKeys · Leaf · MacroHandler · MacroResult · PageReadsResolve · StayedAnswer · TransformStage

import { … } from 'ogygia/vite';

definePlugin

function

A plugin, as the Vite plugin the app lists beside ogygia().

function definePlugin<Options = undefined>(definition: PluginDefinition<Options>): OgygiaPlugin<Options>;

import_keys_hint

function

Cheap source-scan regex matching any of the configured import-attribute key names. Used to skip AST work on hosts that cannot contain region imports.

  • import_keys — Resolved key map from normalize_import_keys.
function import_keys_hint(import_keys: ImportKeys): RegExp;

islandChunkFileName

function

Deterministic client path of a hydrate island's stable name (mirrors the runtime's). SSR bakes it into <ogygia-region entry> as the island's identity — a name, not a file: the content-hashed entry is found through the handoff (the server) and the location maps (the browser, link/location-map.ts), since Kit builds server before client.

function islandChunkFileName(iid: string, appDir?: string): string;

islandId

function

Deterministic short id for a region (stable across dev + build). When salt is set (production OGYGIA_SECRET), ids are not offline-computable (P1-ID). Paths are always posix so SSR/client builds agree across OS path separators.

function islandId(relHostPath: string, index: string | number, salt?: string): string;

islandPublicUrl

function

App-internal URL for islandChunkFileName: /<appDir>/ogygia/… (leading slash, appDir, NO base). It is what SSR bakes onto <ogygia-region entry>; Region.svelte runs it through Kit's asset() at render time, which is the sole authority on base / the assets CDN / relative paths — so a base is never baked here (that would double-apply it). NOT the on-disk output filename.

function islandPublicUrl(iid: string, appDir?: string): string;

normalize_import_keys

function

Merge partial importKeys with DEFAULT_IMPORT_KEYS. Rejects empty strings, non-identifiers, and colliding role names.

  • overrides — Optional overrides for one or more roles.

Returns Fully resolved key map used by the transform.

function normalize_import_keys(overrides?: Partial<ImportKeys> | null): ImportKeys;

ogygia

function

Vite plugin: transforms with { hydrate | defer | preset } imports into islands, serves virtual island modules, and wires signed region endpoints for deferred HTML.

Place before sveltekit() in vite.config.

  • options — Plugin configuration. See OgygiaOptions.

Returns Vite plugins (ogygia pre + island sourcemap fix post). Vite flattens the array.

function ogygia(options?: OgygiaOptions): Plugin[];

regionId

function

Hash an identity string (optional production salt) → 12-char region id.

function regionId(identityKey: string, salt?: string): string;

regionIdentity

function

Cross-host stable identity: posix component path + strategyKey. Drives region ids so multiple hosts / import sites / <A /> usages share one module.

function regionIdentity(componentRelPath: string, mark: {
  strategy: string;
  options?: MarkOptions | null;
}): string;

rewrite_lake_import_to_placeholder

function

Rewrite a lake binding's import to the render-nothing placeholder (client island modules only). Default imports are repointed; named imports drop that specifier (and keep siblings) then add a default import of the placeholder under the same local name.

function rewrite_lake_import_to_placeholder(src: string, local: string, placeholder: string): string;

strategyKey

function

Fingerprint of a region mark for dedupe. Same component path + same key → one wrapper/entry. Every option baked into the wrapper is in the key (a cache TTL, the stitch mode, the warm schedule, a keep name, a margin), so two marks that differ in one never share a wrapper. A held region's key starts region:, apart from a placed wrapper of the same schedule.

function strategyKey(mark: {
  strategy: string;
  options?: MarkOptions | null;
}): string;

wrapperVirtualId

function

The wake region wrapper's component id.

const wrapperVirtualId: (iid: string) => string

CLIENT_BINDING_STUB

const

csr=false CLIENT host binding target. Kit still emits those page nodes; pointing marked imports here (instead of wrappers) keeps N island wrappers/entries out of the page graph so emitFile owns hydrate modules and Rolldown does not thin-facade them. Hydration uses import(entry) only — this stub is never loaded for island JS.

Beside the stub the transform emits import 'ogygia:region/fouc-css/<entry>' so Kit still links stylesheets (FOUC) via CSS-only side effects. Importing the full .svelte JS module dual-owns it with the emitFile island entry and Rolldown thin-facades og-region.*. Omitting CSS entirely orphans rules (scoped class hashes, no stylesheet).

const CLIENT_BINDING_STUB: string

DEFAULT_IMPORT_KEYS

const

Default import-attribute keys — the two-dial grammar. Internal role names stay hydrate/defer (the wire format + runtime keep those anchors); the user-facing ATTRIBUTE names are the values. Override via ogygia({ importKeys }).

  • render attribute → the MODE: static (inline HTML) | deferred (a hole, fetched) | live (a hole that revalidates). Defaults to static.
  • fetch attribute → a deferred hole's TIMING, when its HTML arrives (default load): with { render: 'deferred', fetch: 'visible' }.
  • wake attribute → when an island's JS runs (none: a lake). Never a hole's timing.
const DEFAULT_IMPORT_KEYS: {
  readonly wake: "wake";
  readonly fetch: "fetch";
  readonly render: "render";
  readonly preset: "preset";
  readonly region: "region";
}

MARKDOWN_EXTENSION_API

const

The Vite plugin api key a markdown extension is offered under.

const MARKDOWN_EXTENSION_API = "ogygiaMarkdown"

BuildContext

interface

The build, as one plugin sees it (handed to build).

BuildContext.transform

Run transform on every module (that filter takes) at its stage.

BuildContext.stayed

Answer why a transform of this plugin left imports of a module as written: the findings that weigh a module an island still imports whole ask every plugin's answer (RegionsSeam.whyStayed).

BuildContext.exports

The app's export index (compiler/exports/), for a transform that follows names through barrels.

BuildContext.pinnedImports

For a module's code: the imports that carry a region's identity (a region mark, on a default or a named import). A transform that rewrites imports leaves them as written, so the region the prescan keys on the raw import is the region the transform sees.

BuildContext.regions

The app's regions as the build knows them now, for a tool that names or weighs them.

BuildContext.root

The app's root directory.

BuildContext.routesDir

Kit's routes folder (kit.files.routes), absolute.

BuildContext.dev

vite dev (true) or vite build (false).

BuildContext.routeConfig

A key this plugin reads inside Kit's own config page option (export const config = { <key>: false } in a +page / +layout module, .server included). Read at build time, merged the way Kit merges config (layouts, then the page; later wins), and answered on the server by ctx.routeConfig(key). Literal values only (a boolean, number, string or null); nothing is stripped, because Kit accepts any key inside config.

BuildContext.foreignHydrate

Keep the foreign-hydrate exports on this app's island entries: another app's page may host them and wake them through its own runtime (fragment federation). Off by default — they cost every island ~185 B gz and a preload. It also says this app's pages carry regions this build never compiled (another app's, or ones this plugin's browser half places), so its runtime ships every feature, schedule and island reader a region in the HTML can need. Nothing else says it: a browser half alone (boot and told hooks) hides no schedule.

BuildContext.macro

An import.meta.og.<name>(…) construct this plugin compiles ('code', 'loader'). Plugin macros run after core's own (wire, $, source, store), in plugin order; last: after every other plugin's (bake: it runs code the others may still rewrite). They run on the app's own source only: elsewhere a call fails the build (macro_outside_app).

BuildContext.prescan

Read the modules the build's prescan reads (the app's source and the files packages declare, every one, used or not) that import one of hook.imports; hook.written() after a vite build wrote its client output. An inventory (flags()'s flag sites) is built here.

BuildContext.markup

A source format that becomes Svelte through a preprocessor (markdown): register it, get the island transform to call from that preprocessor.

BuildContext.definers

Calls that define things for the life of the module making them (content, flag): exported as names from module. In dev each such call in a server module is marked with its module's run (./definers.ts), so a definition deleted from the code leaves when the module reloads; the definer reads the run with defining() from

BuildContext.events

Compile core's EVENT emits in, browser and server (ogygia/events: island wakes, server renders, hub mints, navigations) — off, every emit folds away. lazy: measure only once a viewer opens a tool (the page carries a launcher; a preview build).

BuildContext.measure

Record the build's MEASUREMENT data: per-island detail, chunk contents, server source maps, the module map, the embedded maps, the request stats' detail — what a profiler reads.

BuildContext.files

Compile a package's files as app source (their islands, router-css roots): dirs / files absolute, under root (the package's directory). For a plugin's own pages (a UI it serves).

BuildContext.pageModules

Modules that render pages outside Kit's routes (a programmatic router): every component they import gets its whole-tree CSS linked when it renders (componentCssHead() from ogygia/plugin/css). importers: any compiled module importing one of these specifiers is a page module; files: absolute paths that are page modules themselves (compiled ones: app source, or a files() / ogygia.files surface).

BuildContext.pageReads

SEED SHAPING: this plugin answers which top-level page.data keys a module reads (@ogygia/data-shake). One plugin at most. Without one, every region that reads the page gets all of page.data, and every server hole looks it up.

interface BuildContext {/*…*/}
transform(transform: StageTransform): void;
stayed(answer: StayedAnswer): void;
readonly exports: ExportsSeam;
readonly pinnedImports: (code: string) => (decl: PinnedDecl) => boolean;
readonly regions: RegionsSeam;
readonly root: string;
readonly routesDir: string;
readonly dev: boolean;
routeConfig(key: string): void;
foreignHydrate(): void;
macro(name: string, handler: MacroHandler, options?: {
    last?: boolean;
  }): void;
prescan(hook: PrescanHook): void;
markup(source: MarkupSource): MarkupRegions;
definers(module: string, names: readonly string[]): void;
events(options?: {
    lazy?: boolean;
  }): void;
measure(): void;
files(scan: {
    root: string;
    dirs?: string[];
    files?: string[];
  }): void;
pageModules(modules: {
    importers?: string[];
    files?: string[];
  }): void;
pageReads(reads: PageReads): void;

ExportMap

interface

ExportMap.id

ExportMap.entries

the barrel's usable names

ExportMap.pure

pure barrel → the import can be dropped once every name moved; impure → kept for effects

ExportMap.left

null: a barrel the policy goes through; else why it does not (entries is then empty)

ExportMap.opaque

some names could not be seen (a star into the unparsable): unknown names stay on the barrel

ExportMap.deps

every module this map depends on: a change to any of them invalidates the map

ExportMap.provisional

built while a neighbour was still being built by another walk: served, not cached

ExportMap.cycles

ids on the walk stack this build ran into (a cycle): the map lacks THEIR names, so it is cached only once the walk that owns them has closed the ring (the set is empty there)

interface ExportMap {/*…*/}
id: string;
entries: Map<string, Entry>;
pure: boolean;
left: null | "impure" | "kept" | "outside-project";
opaque: boolean;
deps: Set<string>;
provisional: boolean;
cycles: Set<string>;

ExportsSeam

interface

The app's export index: each barrel's names to the modules that define them, over one parse of each module for the whole app, resolved as the module being transformed resolves.

ExportsSeam.map

The map of the barrel at file (as spec named it), or null when policy does not go through it.

interface ExportsSeam {/*…*/}
map(file: string, spec: string, policy: Policy, t: TransformContext): Promise<ExportMap | null>;

MacroContext

interface

What a macro knows about the module it rewrites.

MacroContext.id

The module id, query stripped.

MacroContext.rel

The id relative to the app root, POSIX (a stable identity for stamps).

MacroContext.root

MacroContext.alias

The app's resolved aliases ($lib, …), for a macro that resolves or bundles imports.

MacroContext.markupExts

Markup extensions whose <script> blocks hold the macro calls (.svelte).

MacroContext.regions

The code a macro rewrites in this module's text code: a JS module whole, a .svelte component's <script> blocks, a markdown page's (.svx, .md) <script> blocks (not its fenced code); null for any other module. A call left outside them fails the build (macro_in_markup), and so does one a handler leaves in a markdown page's script.

MacroContext.watch

Name a file the rewrite read: an edit to it transforms this module again (dev).

interface MacroContext {/*…*/}
readonly id: string;
readonly rel: string;
readonly root: string;
readonly alias: readonly AliasEntry[];
readonly markupExts: readonly string[];
regions: (code: string) => JsRegion[] | null;
watch: (file: string) => void;

MarkdownExtension

interface

A markdown extension one plugin offers another's markdown pipeline (its Vite plugin's api[MARKDOWN_EXTENSION_API]): the one contract both sides compile against. R is the pipeline's rehype entry.

MarkdownExtension.name

Who offers it: one extension per name, the last config's.

MarkdownExtension.cache_key

What changes the compiled output besides the document and the pipeline's own settings: part of the document cache key. Read on every compile.

MarkdownExtension.rehype

Rehype entries, staged like the pipeline's own (after the app's own entries of each stage).

MarkdownExtension.finish

After mdsvex, before the island transform: rewrite the compiled module.

interface MarkdownExtension<R = unknown> {/*…*/}
name: string;
cache_key: () => string;
rehype?: readonly R[];
finish?: (code: string, filename: string) => MarkdownFinish;

MarkdownFinish

interface

What a markdown extension's finish hands back.

MarkdownFinish.code

The compiled module, rewritten.

MarkdownFinish.lines

Module-script lines to add (imports, exports).

MarkdownFinish.dynamic

The body now renders a component or an expression: it is never emitted as a static region.

MarkdownFinish.files

Files the output names (an image a post shows): watched like the document's own, and a kept compile of the document whose file is gone compiles again, so the extension's check runs.

interface MarkdownFinish {/*…*/}
code: string;
lines: string[];
dynamic: boolean;
files?: readonly string[];

MarkupRegions

interface

What the build hands back for a markup source: run the region transform on preprocessed Svelte.

MarkupRegions.transform

Rewrite the marked imports in already-preprocessed Svelte and register its regions. The code, or null when nothing changed.

interface MarkupRegions {/*…*/}
transform: (source: string, filename: string) => string | null;

MarkupSource

interface

A source format that becomes Svelte only through a preprocessor (markdown → Svelte): how its islands and its modules' CSS reach the build.

MarkupSource.extensions

The format's file extensions (['.svx', '.md']).

MarkupSource.scan

Discover the format's islands up front (build start, dev included): read each file, turn it into Svelte, and hand that to transform so its islands are registered before chunks emit.

MarkupSource.modules

The format's modules, absolute path → their post-preprocess Svelte source. A module only ever renders on the server, so no client chunk carries its CSS: the build ships, as one client asset per module, the scoped CSS of its own <style> and of every component it imports (and plain style imports). The plugin keeps filling it ([path, source] pairs); the build reads it late.

interface MarkupSource {/*…*/}
extensions: readonly string[];
scan?(ctx: {
    root: string;
    readFile: (abs: string) => string | null;
  }): void | Promise<void>;
modules?: Iterable<readonly [string, string]>;

OgygiaOptions

interface

Options for the {@link ogygia } Vite plugin. The root is the region system itself — its defaults (visible), its named presets (referenced from a use site by a LITERAL preset: 'name': import X from '…' with { preset: 'name' }), its holes' capability lifetimes — beside the client router. Feature packages are Vite plugins listed beside it (plugins: [ogygia(), flags(), sveltekit()]).

OgygiaOptions.visible

Defaults for regions that wake 'visible' (wake: 'visible' / render + wake: 'visible') without their own margin (via a preset).

OgygiaOptions.presets

Named strategy bundles. Reference one from an import: import Chart from '$lib/Chart.svelte' with { preset: 'chart' };

OgygiaOptions.ttl

How long a deferred/live hole's signed capability URL stays valid, in seconds (default 3600). Clamped to [60, 86400]. Keep short for harvested-URL risk. Holes outlive this automatically where they must: on prerendered and postrendered pages, and on a page a load marks shared-cacheable (setHeaders({ 'cache-control': 'public, s-maxage=…' })), where an anonymous hole is signed for the page's cache life; a hole on an older cached copy renews itself when it wakes.

OgygiaOptions.maxPageAge

The oldest a cached copy of a page can be and still get its holes, in seconds (default 691200, 8 days). An anonymous hole whose capability expired while a cache kept its page renews itself for up to this long after that expiry; past it, the hole keeps its fallback. Raise it to the longest your CDN may serve a page when the page does not say so in its cache-control. 0 turns renewal off. Unlike ttl it never lengthens a hole URL's life (a renewed URL lives ttl), and a hole bound to a session never renews. A renewable URL replays its props: keep hole props to routing keys (a locale, a page), and read anything sensitive at render.

OgygiaOptions.router

Client-side SPA router — app-wide, on by default. It intercepts same-origin links, swaps <body>, merges <head>, and keeps data-ogygia-keep chrome across navigations. No component to place: the server handle injects the runtime + the ogygia-router meta into every page.

  • true (default) — router on, View Transitions on, form continuity on.
  • false — router off (the whole feature is tree-shaken out; same-origin links do full MPA loads, and form continuity — which rides SPA navigation — goes with it).
  • { viewTransitions: false } — router on, but no View Transitions API on navigation.
  • { forms: false } — router on, but an island's half-filled form fields are NOT carried across SPA navigation (continuity off).
  • { serverDelta: true } — opt IN to server-delta nav: an SPA nav tells the server (via an x-ogygia-known header) which islands it already has live, so the server SKIPS re-rendering the unchanged ones and the client keeps them running. OFF by default (it is a new client↔server protocol); when off the client never sends the header and the server always full-renders.

Per-page escape hatch (no second config): a page opts itself out of View Transitions by emitting <svelte:head><meta name="ogygia-router" content="plain" /></svelte:head> — the handle injects the app default but a page that sets its own meta wins.

OgygiaOptions.importKeys

Rename the import-attribute keys claimed by the transform. Defaults stay wake / fetch / render / preset / region. Escape hatch if another tool already uses those names on the same imports.

Preset definitions (OgygiaOptions.presets) still use the standard render / wake / fetch / … keys: only the with { … } spellings in source change.

OgygiaOptions.rateLimit

Per-IP budget for the signed island endpoint served by ogygiaHandle(). Default { max: 60, windowMs: 60_000 }. Pass false to disable.

OgygiaOptions.sessionCookie

Cookie name to seal into the region MAC (opt-in). Empty/prerender stays unbound. Harvested capability URLs then fail verification without that cookie. Default false (unbound).

OgygiaOptions.standalone

interface OgygiaOptions {/*…*/}
import { ogygia } from 'ogygia/vite';
export default defineConfig({
  plugins: [
    ogygia({
      visible: { margin: '200px' },
      presets: { chart: { wake: 'visible', margin: '200px' } },
      ttl: 3600
    }),
    sveltekit()
  ]
});
visible?: {
    margin?: string;
  };
presets?: Record<string, OgygiaPreset>;
ttl?: number;
maxPageAge?: number;
router?: boolean | {
    viewTransitions?: boolean;
    forms?: boolean;
    serverDelta?: boolean;
  };
importKeys?: Partial<ImportKeys>;
rateLimit?: false | OgygiaRateLimit;
sessionCookie?: false | string;
standalone?: boolean;

OgygiaPlugin

interface

The value a plugin's factory returns: a Vite plugin carrying its definition.

OgygiaPlugin.[PLUGIN]

interface OgygiaPlugin<Options = unknown> extends Plugin {/*…*/}
readonly [PLUGIN]: PluginDefinition<Options>;

OgygiaPreset

interface

Named strategy bundle referenced from source via with { preset: 'name' } (or the renamed importKeys.preset key).

A preset speaks the SAME grammar as an inline import: a render mode with its timing (fetch for a deferred hole, wake for an island), plus the tuning options that aren't allowed inline (margin, maxAge, …).

OgygiaPreset.render

Delivery mode (the render import attribute): 'static' (default — an island that hydrates) | 'deferred' (a hole whose HTML is fetched, on its fetch timing) | 'live' (a hole that revalidates).

OgygiaPreset.wake

When an island's JS runs (the wake import attribute): 'load' | 'idle' | 'visible' | 'interaction' | a CSS media query | 'none' (a frozen lake). With render: 'live', the revalidate schedule. Never a deferred hole's timing — that is fetch.

OgygiaPreset.fetch

A render: 'deferred' hole's timing — when its HTML arrives (the fetch import attribute): 'load' (default) | 'idle' | 'visible' | 'interaction' | a CSS media query.

OgygiaPreset.margin

IntersectionObserver rootMargin when the schedule is 'visible'.

OgygiaPreset.maxAge

A hole (fetch) — response cache max-age for the hole's HTML: seconds (number) or a duration string ('30s' | '5m' | '1h'). Absent or 0 → no-store: the hole is dynamic, re-rendered on every request. A positive value opts into a private, max-age browser cache. Signed into the hole's endpoint so a harvested URL can't be re-pointed at a longer cache.

With render: 'live' this is instead the client revalidate staleness — use a duration string to stay unit-explicit across both.

OgygiaPreset.onExpire

render: 'live' — past maxAge, whether to clear the hole ('empty') or refetch ('fetch').

OgygiaPreset.prefetch

A hole (fetch) — warm the hole's HTML into the frame store on this schedule ('load' | 'idle' | 'visible' | a media query) while fetch still decides when it swaps in. An on-demand hole (fetch: 'interaction') then has its bytes before the first hover: the gesture joins the warm frame instead of paying the origin round trip. Never 'interaction' — that is the swap schedule, fetch's job.

OgygiaPreset.revalidate

render: 'live' — the revalidate schedule (false disables). Defaults to wake.

OgygiaPreset.keep

Continuity name (the keep import attribute): the live island relocates across SPA navigation instead of remounting when the next page carries the same name.

interface OgygiaPreset {/*…*/}
render?: "static" | "deferred" | "live";
wake?: string;
fetch?: string;
margin?: string;
maxAge?: number | string;
onExpire?: "empty" | "fetch";
prefetch?: string;
revalidate?: false | string;
keep?: string;

OgygiaRateLimit

interface

Per-IP budget for the signed deferred-region / lake-remount endpoint.

OgygiaRateLimit.max

Max requests per window (default 60). 0 disables allowing any.

OgygiaRateLimit.windowMs

Sliding window length in milliseconds (default 60_000).

interface OgygiaRateLimit {/*…*/}
max?: number;
windowMs?: number;

PageReads

interface

What a seed-shaping plugin answers (handed to BuildContext.pageReads). Module ids are query-less, with forward slashes. Core unions the answers over each island's closure and walks each server hole's graph; 'unknown' anywhere ships (or looks up) all of page.data.

PageReads.module

A module the build compiles, in its source form (before ogygia's own rewrites). Build only.

PageReads.settle

Once in the client leg, before core asks keys: settle what needs the bundler (a helper in another module that the page is handed to).

PageReads.keys

The keys a module reads, 'unknown', or null (it was never seen reading the page).

PageReads.why

Why a module answers 'unknown' (the build's seed report, the profiler).

PageReads.dev

Dev, for the profiler: what these files read together (an island's component and the app modules below it), as the build would answer; null when none reads the page.

interface PageReads {/*…*/}
module(id: string, code: string): void;
settle(resolve: PageReadsResolve): Promise<void>;
keys(id: string): ReadonlySet<string> | "unknown" | null;
why(id: string): PageReadWhy | null;
dev(files: readonly string[], resolve: PageReadsResolve): Promise<{
    keys: string[] | "unknown" | null;
    why: {
      file: string;
      line: number | null;
      why: string;
    }[];
  }>;

PageReadWhy

interface

Why a module answers 'unknown': the construct, and its line.

PageReadWhy.why

PageReadWhy.line

interface PageReadWhy {/*…*/}
readonly why: string;
readonly line: number | null;

PinnedDecl

interface

An import declaration, as BuildContext.pinnedImports reads it.

PinnedDecl.attribute_keys

PinnedDecl.specs

interface PinnedDecl {/*…*/}
readonly attribute_keys: readonly string[];
readonly specs: readonly {
    readonly local: string;
  }[];

PluginDefinition

interface

What a plugin is: the argument to definePlugin.

PluginDefinition.name

The plugin's package name ('@ogygia/postrender'): its identity.

PluginDefinition.server

The SERVER realm: a module whose default export is defineServer({…}) (ogygia/plugin), as a file: URL or an absolute path — import.meta.resolve('./server.ts').

PluginDefinition.client

The BROWSER realm: a module whose default export is defineClient({…}) (ogygia/plugin/client), booted on every page — same form as server.

PluginDefinition.options

Settings for every realm (JSON: no functions, no clients — live objects are configured at runtime, in hooks.server.ts).

PluginDefinition.enforce

Run before ('pre') or after ('post') the other plugins, in every realm.

PluginDefinition.needs

The plugins this one needs listed beside it: each one's package name, its call and the package to import it from. One the app does not list fails the build (plugin_needs_plugin), naming the line to add.

PluginDefinition.build

Build-time contributions, with the build context.

interface PluginDefinition<Options = unknown> {/*…*/}
name: string;
server?: string;
client?: string;
options?: Options;
enforce?: "pre" | "post";
needs?: readonly {
    name: string;
    call: string;
    from: string;
  }[];
build?(b: BuildContext): void;

Policy

interface

Which barrels a caller may go through, and how far.

Policy.candidate

May this resolved module be treated as a barrel at all?

Policy.forced

Is this module a barrel even though it is impure?

Policy.kept

Is this module kept whatever it looks like?

Policy.follow_packages

Follow a star into node_modules?

interface Policy {/*…*/}
candidate(id: string, spec: string): boolean;
forced(id: string, spec: string): boolean;
kept(id: string, spec: string): boolean;
follow_packages: boolean;

PrescanHook

interface

A plugin's reader of the prescan (b.prescan): the modules it asked for, as the prescan reads them, and the end of a build.

PrescanHook.imports

Only modules that import one of these specifiers are handed over.

PrescanHook.module

One module the prescan read: its absolute path, its identity (package-relative in a package's declared files, else relative to the app root; POSIX), its source.

PrescanHook.written

A vite build wrote its client output (the last leg, on the main thread).

interface PrescanHook {/*…*/}
readonly imports: readonly string[];
module(m: {
    readonly file: string;
    readonly rel: string;
    readonly code: string;
  }): void;
written?(): void;

RegionsSeam

interface

The live region table (read at call time, so it is complete once the app's islands are known).

RegionsSeam.names

island id → its component's name

RegionsSeam.hosts

Each module that marks region imports (a host, by its absolute path) → the module ids its regions are built from: their components and the modules ogygia mints for them.

RegionsSeam.whyStayed

Why the module at file stayed as these modules import it, in the browser's leg: every plugin's answer (BuildContext.stayed), in BARREL_LEFT_REASONS order (none: no plugin left it).

interface RegionsSeam {/*…*/}
names(): Record<string, string>;
hosts(): ReadonlyMap<string, ReadonlySet<string>>;
whyStayed(file: string, importers: Iterable<string>): BarrelLeftReason[];

StageTransform

interface

A transform at a stage around the region transform: ordering is the stage, not list position.

StageTransform.stage

StageTransform.filter

Which modules (by full id); every module when absent.

StageTransform.transform

interface StageTransform {/*…*/}
stage: TransformStage;
filter?(id: string): boolean;
transform(t: TransformContext): void | Promise<void>;

TransformContext

interface

One module, as a stage transform sees it.

TransformContext.id

The module id, query included.

TransformContext.code

The module's code as the stage received it (no byte-order mark).

TransformContext.edit

The stage's edits, by offsets into code: every transform of a stage edits the code it received, and the stage emits one result and one source map.

TransformContext.environment

The bundler's environment (client, ssr).

TransformContext.resolve

A specifier resolved from importer as the bundler resolves it now; null when it cannot be (unresolvable, or external).

TransformContext.watch

Re-transform this module when file changes (dev).

interface TransformContext {/*…*/}
readonly id: string;
readonly code: string;
readonly edit: MagicString;
readonly environment: string;
resolve(spec: string, importer: string): Promise<string | null>;
watch: (file: string) => void;

Entry

type

type Entry = Leaf | "own" | "ambiguous";

ImportKeys

type

Import-attribute key names claimed by the transform (with { wake | fetch | render | preset | region }). Override via ogygia({ importKeys }) when another tool already uses the default names.

type ImportKeys = {
  wake: string;
  fetch: string;
  render: string;
  preset: string;
  region: string;
};

Leaf

type

Where an importer can go for a name: import { name } from id (default: a default import), or import * as local from id (namespace).

type Leaf = {
  id: string;
  name: string;
} | {
  id: string;
  namespace: true;
};

MacroHandler

type

A import.meta.og.<name> macro: rewrites a module that contains the marker (it is called only then), before the island transform or region minting see it. Returns the new code (the same string when nothing changed), or the edits that make it: edits keep the module's source map, a string loses it.

type MacroHandler = (code: string, m: MacroContext) => MacroResult | Promise<MacroResult>;

MacroResult

type

What a macro answers: the new code (the same string when nothing changed), or the edits that make it, which keep the module's source map.

type MacroResult = string | readonly Edit[];

PageReadsResolve

type

A specifier resolved from an importer, as the bundler resolves it (null: it does not).

type PageReadsResolve = (specifier: string, importer: string) => Promise<{
  id: string;
} | null | undefined>;

StayedAnswer

type

Why imports of the module at file stayed as written in these importers (ids, queries allowed), in the bundler environment environment; none when this plugin left none of them.

type StayedAnswer = (file: string, importers: readonly string[], environment: string) => readonly BarrelLeftReason[];

TransformStage

type

Where a plugin's transform runs: on the module as written, before the region transform ('source'), or on what the region transform made of it ('post').

type TransformStage = "source" | "post";