Share code across multiple apps with a monorepo.
Monorepo Structure
my-monorepo/
āāā apps/
ā āāā web/ # Main SvelteKit app
ā ā āāā package.json
ā ā āāā src/
ā āāā admin/ # Admin SvelteKit app
ā ā āāā package.json
ā āāā docs/ # Documentation site
āāā packages/
ā āāā ui/ # Shared components
ā ā āāā package.json
ā ā āāā src/
ā ā āāā Button.svelte
ā ā āāā index.js
ā āāā core/ # Business logic
ā ā āāā package.json
ā ā āāā src/
ā ā āāā cart.svelte.js
ā āāā config/ # Shared configs
ā āāā eslint/
ā āāā tsconfig/
āāā package.json
āāā pnpm-workspace.yaml # or npm/yarn workspaces
āāā turbo.json # Turborepo config
Workspace Configuration
yaml# pnpm-workspace.yaml packages: - 'apps/*' - 'packages/*'
Sharing Svelte Components
json// packages/ui/package.json { "name": "@myorg/ui", "svelte": "./src/index.js", "exports": { ".": { "svelte": "./src/index.js" } } }
javascript// packages/ui/src/index.js export { default as Button } from './Button.svelte'; export { default as Card } from './Card.svelte';
javascript// apps/web - Using shared components import { Button, Card } from '@myorg/ui';
Sharing Runes Logic
javascript// packages/core/src/cart.svelte.js export class Cart { items = $state([]); get total() { return this.items.reduce((sum, i) => sum + i.price, 0); } add(item) { this.items = [...this.items, item]; } }
This works in Svelte apps, React apps (with adapter), or Node.js scripts!
Build Tools
Turborepo - Fast builds with caching
bashnpx create-turbo@latest
Nx - Full-featured monorepo tool
bashnpx create-nx-workspace
š Turborepo