Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions examples/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
node_modules

# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions examples/svelte/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
38 changes: 38 additions & 0 deletions examples/svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# sv

Everything you need to build a Svelte project, powered by [`sv`](https://github.com/sveltejs/cli).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```sh
# create a new project in the current directory
npx sv create

# create a new project in my-app
npx sv create my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```sh
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```sh
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.
9 changes: 9 additions & 0 deletions examples/svelte/backend/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { registry } from "./registry";

export type Registry = typeof registry;

registry.runServer({
cors: {
origin: "http://localhost:5173",
},
});
25 changes: 25 additions & 0 deletions examples/svelte/backend/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { actor, setup } from "@rivetkit/actor";

export const counter = actor({
onAuth: () => {
// Configure auth here
},
state: { count: 0 },
actions: {
increment: (c, x: number) => {
console.log("incrementing by", x);
c.state.count += x;
c.broadcast("newCount", c.state.count);
return c.state.count;
},
reset: (c) => {
c.state.count = 0;
c.broadcast("newCount", c.state.count);
return c.state.count;
},
},
});

export const registry = setup({
use: { counter },
});
30 changes: 30 additions & 0 deletions examples/svelte/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "frontend",
"private": true,
"version": "0.0.1",
"type": "module",
"scripts": {
"dev": "run-p dev:web dev:api",
"dev:web": "vite dev",
"dev:api": "tsx --watch backend/index.ts",
"build": "vite build",
"preview": "vite preview",
"prepare": "svelte-kit sync || echo ''",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@rivetkit/actor": "workspace:*",
"@rivetkit/svelte": "workspace:*",
"@sveltejs/adapter-auto": "^6.0.0",
"@sveltejs/kit": "^2.22.0",
"@sveltejs/vite-plugin-svelte": "^6.0.0",
"@types/node": "^22.13.9",
"svelte": "^5.0.0",
"svelte-check": "^4.0.0",
"typescript": "^5.0.0",
"vite": "^7.0.4",
"npm-run-all": "^4.1.5",
"tsx": "^3.12.7"
}
}
13 changes: 13 additions & 0 deletions examples/svelte/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://svelte.dev/docs/kit/types#app.d.ts
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
11 changes: 11 additions & 0 deletions examples/svelte/src/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>
5 changes: 5 additions & 0 deletions examples/svelte/src/lib/actor-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createClient, createRivetKit } from "@rivetkit/svelte";
import type { Registry } from "../../backend";

const client = createClient<Registry>(`http://localhost:8080`);
export const { useActor } = createRivetKit(client);
1 change: 1 addition & 0 deletions examples/svelte/src/lib/assets/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/svelte/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// place files you want to import through the `$lib` alias in this folder.
1 change: 1 addition & 0 deletions examples/svelte/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ssr = false;
11 changes: 11 additions & 0 deletions examples/svelte/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script lang="ts">
import favicon from '$lib/assets/favicon.svg';
let { children } = $props();
</script>

<svelte:head>
<link rel="icon" href={favicon} />
</svelte:head>

{@render children?.()}
37 changes: 37 additions & 0 deletions examples/svelte/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<script lang="ts">
import { onMount } from "svelte";
import { useActor } from "../lib/actor-client";

let count = $state(0);
const counter = useActor({ name: 'counter', key: ['test-counter'] });

$effect(()=>{
console.log('status', counter?.isConnected);
counter?.useEvent('newCount', (x: number) => {
console.log('new count event', x);
count=x;
});
//also works
// counter.connection?.on('newCount', (x: number) => {
// console.log('new count event', x);
// count=x;
// })
})
const increment = () => {
counter?.connection?.increment(1);

};
const reset = () => {
counter?.connection?.reset();

};

// $inspect is for debugging, but ensure it's used correctly
$inspect('useActor is connected', counter?.isConnected);
</script>

<div>
<h1>Counter: {count}</h1>
<button onclick={increment}>Increment</button>
<button onclick={reset}>Reset</button>
</div>
3 changes: 3 additions & 0 deletions examples/svelte/static/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# allow crawling everything by default
User-agent: *
Disallow:
24 changes: 24 additions & 0 deletions examples/svelte/svelte.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import adapter from "@sveltejs/adapter-auto";
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";

/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://svelte.dev/docs/kit/integrations
// for more information about preprocessors
preprocess: vitePreprocess(),

kit: {
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
adapter: adapter(),
alias: {
$: "./src",
"$/*": "./src/*",
$backend: "./backend",
"$backend/*": "./backend/*",
},
},
};

export default config;
24 changes: 24 additions & 0 deletions examples/svelte/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "bundler",
"baseUrl": "./",
"paths": {
"$/": ["./src/"],
"$backend/": ["./backend/"]
}
}
// Path aliases are handled by https://svelte.dev/docs/kit/configuration#alias
// except $lib which is handled by https://svelte.dev/docs/kit/configuration#files
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
4 changes: 4 additions & 0 deletions examples/svelte/turbo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"$schema": "https://turbo.build/schema.json",
"extends": ["//"]
}
6 changes: 6 additions & 0 deletions examples/svelte/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";

export default defineConfig({
plugins: [sveltekit()],
});
2 changes: 1 addition & 1 deletion examples/sync/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src", "tests"],
"include": ["src", "backend"],
"exclude": ["node_modules", "dist"]
}
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,10 @@
"@hono/node-ws": "^1.1.7",
"esbuild": "^0.25.1"
},
"packageManager": "[email protected]+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808"
"packageManager": "[email protected]+sha512.2d92c86b7928dc8284f53494fb4201f983da65f0fb4f0d40baafa5cf628fa31dae3e5968f12466f17df7e97310e30f343a648baea1b9b350685dafafffdf5808",
"pnpm": {
"onlyBuiltDependencies": [
"esbuild"
]
}
}
24 changes: 24 additions & 0 deletions packages/frameworks/svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules

# Output
.output
.vercel
.netlify
.wrangler
/.svelte-kit
/build
/dist

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
1 change: 1 addition & 0 deletions packages/frameworks/svelte/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
engine-strict=true
58 changes: 58 additions & 0 deletions packages/frameworks/svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Svelte library

Everything you need to build a Svelte library, powered by [`sv`](https://npmjs.com/package/sv).

Read more about creating a library [in the docs](https://svelte.dev/docs/kit/packaging).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```sh
# create a new project in the current directory
npx sv create

# create a new project in my-app
npx sv create my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```sh
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

Everything inside `src/lib` is part of your library, everything inside `src/routes` can be used as a showcase or preview app.

## Building

To build your library:

```sh
npm pack
```

To create a production version of your showcase app:

```sh
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://svelte.dev/docs/kit/adapters) for your target environment.

## Publishing

Go into the `package.json` and give your package the desired name through the `"name"` option. Also consider adding a `"license"` field and point it to a `LICENSE` file which you can create from a template (one popular option is the [MIT license](https://opensource.org/license/mit/)).

To publish your library to [npm](https://www.npmjs.com):

```sh
npm publish
```
Loading