Vite Plugin
The realtime() Vite plugin scans src/live/ and generates $live/* virtual imports.
Setup
// vite.config.js
import { sveltekit } from '@sveltejs/kit/vite';
import uws from 'svelte-adapter-uws/vite';
import realtime from 'svelte-realtime/vite';
export default {
plugins: [sveltekit(), uws(), realtime()]
}; How it works
- The plugin watches
src/live/for.jsand.tsfiles - It parses each file for
live(),live.stream(),live.cron(), etc. exports - It generates client stub modules under the
$live/virtual import prefix live()exports become async RPC functionslive.stream()exports become Svelte store factories- Server-only code is stripped from the client bundle
What gets generated
For a file src/live/chat.js that exports:
sendMessagevialive()messagesvialive.stream()
The plugin generates $live/chat with:
sendMessage(text)- calls the server function over WebSocketmessages- a Svelte store that subscribes to the'messages'topic
File structure
src/live/
├── chat.js => $live/chat
├── todos.js => $live/todos
└── admin/
└── users.js => $live/admin/users Nested directories map to nested import paths.
Was this page helpful?