Reference
Packaging
Publish Svelte components that become islands in someone else's ogygia app. Ship plain components and let the app mark them, or declare ogygia.files in your package.json to ship your own marks, server islands and route tables.
On this page
A mark is read by the build of the app that compiles it. So there are two ways to ship islands in an npm package, and most packages need only the first:
- Ship plain components, and let the app mark them. The app writes
with { wake: 'visible' }on its own import, because only the app knows where the component sits on its page. Your package is an ordinary Svelte library with nothing ogygia-specific in it. - Mark inside your package. When the mark belongs to your component, such as a panel whose search box is always an island, or a route table you ship, list those files under
ogygia.filesin yourpackage.json. The app’s build then compiles them like its own source.
The first, from the app’s side, is one line:
<script>
import Widget from 'my-widgets/Widget.svelte' with {
wake: 'visible'
};
</script>
<Widget count={3} />App-marked components
Ship each .svelte file as source and export it with the svelte condition, the shape @sveltejs/package produces. The app’s own Svelte compiles it, so lang="ts" in your components is fine. If your library builds with tsdown, @ogygia/tsdown-plugin-svelte produces this shape in the same build as your .ts, with the TypeScript stripped and a .svelte.d.ts beside each component.
The island’s generated module imports your component by the same specifier the app wrote, from the app’s own file. If that specifier doesn’t resolve there (the package isn’t installed in the app, or exports doesn’t list the subpath with a svelte condition), the build fails with island_import_unresolved.
The boundary rules apply to your component as to any island: props cross as copies, a plain function prop doesn’t cross, and state the component changes lives in its own $state.
Export from an index
The app can mark a named import from your index too. The island imports that one export by name, and the bundler drops the rest. You ship nothing for it.
One with covers every name in its braces, so the app puts components with different schedules, and anything that isn’t a component, on separate lines (region_binding_not_component).
{
"name": "my-widgets",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.mts",
"svelte": "./dist/index.mjs",
"default": "./dist/index.mjs"
},
"./Widget.svelte": {
"types": "./dist/Widget.svelte.d.ts",
"svelte": "./dist/Widget.svelte"
}
},
"peerDependencies": {
"svelte": "^5.0.0"
}
}<script>
import { Widget } from 'my-widgets' with { wake: 'visible' };
</script>
<Widget count={3} />Package-marked islands
The app’s build compiles only its own source, so a mark written inside node_modules does nothing by default. Declare the files that carry marks under ogygia.files in your package.json:
The field works like npm’s files. A directory includes everything under it, globs are allowed, and every path is relative to the package and must stay inside it. The app configures nothing. When its build starts, ogygia reads the package.json of each package in the app’s dependencies and devDependencies, and treats each declared file as app source:
- It’s compiled like
src/..svelte,.tsand.jsfiles alike, so a marked import in a shipped route table works. Macros such asimport.meta.og.$and wire codecs work in declared files too, and nowhere else innode_modules(macro_outside_app,transportable_unregistered). - It’s found before the bundler starts. The runtime’s features and the server’s region table include your regions, so a server island inside your package fills like one in the app.
- It’s kept out of Vite’s pre-bundling and bundled into the server (
optimizeDeps.excludeandssr.noExternal), so the app’s plugins see it. - Its regions are named
<package>/<path>, not by where the package sits on disk, so the same build gives the same names on any machine.
Only the app’s direct dependencies are read. A package that reaches the app through another package isn’t, so list it in the app’s own package.json.
In the example, a panel marks its own islands. The app imports Panel with no mark: the panel is server HTML, the counter inside it wakes on load, and the badge is a server island.
Ship a route table
A route table for the server router is an ordinary export of a declared .ts file. Its marked imports work because the file is declared. The app spreads it into its own table, and lists @ogygia/router and its router() plugin.
When the declaration is wrong or missing
- A marked
.tsor.jsfile that isn’t declared compiles as plain code, so its marks do nothing. The build warns (package_marks_undeclared). - A marked
.sveltefile that isn’t declared is compiled when the bundler reaches it, which is after the build has picked the runtime’s features. A region that needs a feature nothing else uses then warns (runtime_marks_late) or fails the server build (server_features_late). Declare it. filesthat isn’t a list of strings, or a path outside the package, fails the build (package_files_not_array,package_files_escapes).- A path that doesn’t exist is skipped with a warning (
package_files_missing).
{
"name": "my-widgets",
"type": "module",
"exports": {
"./Panel.svelte": {
"types": "./src/widgets/Panel.svelte.d.ts",
"svelte": "./src/widgets/Panel.svelte"
},
"./routes": "./src/routes.ts"
},
"peerDependencies": {
"ogygia": "^0.16.0",
"@ogygia/router": "^0.16.0"
},
"ogygia": {
"files": [
"./src/widgets",
"./src/pages/**/*.svelte",
"./src/routes.ts"
]
}
}<script>
import Tally from './Tally.svelte' with { wake: 'load' };
import Badge from './Badge.svelte' with {
render: 'deferred'
};
</script>
<section>
<h2>Team</h2>
<Tally start={3} />
<Badge org="acme">
{#snippet ogygiaFallback()}<span>Loading…</span>{/snippet}
</Badge>
</section><script>
import Panel from 'my-widgets/Panel.svelte';
</script>
<Panel />import { page } from '@ogygia/router';
import Board from './pages/Board.svelte' with { wake: 'load' };
import Summary from './pages/Summary.svelte';
export const widget_table = {
'/board': page(Board, {
load: () => ({ title: 'Live board' })
}),
'/summary': page(Summary)
};import { routes, page } from '@ogygia/router';
import { widget_table } from 'my-widgets/routes';
import Home from '$lib/Home.svelte';
export const app = routes({ '/': page(Home), ...widget_table });Shipping source
A declared file reaches the app’s build as you ship it, and the app compiles it. So ship .svelte files as source, and ship .ts or .js with every with { … } clause still there. The simplest way is to point exports and ogygia.files at your src/ files, as the examples above do; the app’s Vite compiles TypeScript. If you transpile, check that the output keeps import attributes. A tool that drops them leaves the marks out silently, and since a declared file isn’t warned about, the regions are just plain components.
Keep the placement rules of app code in your package too: a content collection stays in a .server.ts file, and a server-only module stays server-only.
Importing ogygia
A package that imports ogygia itself, for a declared region or for the context bridge in a shared layout, lists it as a peer dependency. One rule then applies to every build that touches it: never bundle ogygia into a library. Its import paths resolve to modules that exist only inside the app’s Vite build, and its runtime keeps registries that must be one per app. Leave the import as written, the way you leave $app/* and $env/*. Shipping source, as above, does that already; the rule matters when a build step bundles.
In a monorepo it spreads further than you’d expect. Vite’s library mode bundles workspace dependencies by default, so one import { setContext } from 'ogygia' in a shared package ends up in the bundle of every package that depends on it. Each of those builds needs ogygia external too, even though none of them imports it. The usual fix covers it and everything like it at once: keep every bare import external.
import path from 'node:path';
import { defineConfig } from 'vite';
export default defineConfig({
build: {
lib: { entry: './src/index.ts', formats: ['es'] },
rollupOptions: {
external: (id) =>
!id.startsWith('.') && !path.isAbsolute(id)
}
}
});Do and don’t
- Do ship plain components and let the app choose the schedule, unless the mark is part of what your component is.
- Do export
.sveltefiles with thesveltecondition. - Do declare every file that carries a mark, a macro or a wire codec in
ogygia.files. - Do list
ogygia(and any@ogygia/*package you import) as a peer dependency, on the app’s version. - Don’t bundle
ogygia, orsvelte, into your package. - Don’t rely on a transitive install: the app lists your package in its own
package.json.