Vite + Svelte
A plain Vite app with the same Svelte items and the same reduced-motion branch.
Prerequisites
You need a Vite app with Svelte 5, Tailwind CSS v4 and the #lib import that maps to src/lib.
- Node.js 20 or newer.
- Svelte 5 with the svelte-ts template.
- Tailwind CSS v4 through @tailwindcss/vite.
- The #lib and #lib/* entries in package.json imports, plus the same paths in tsconfig for the CLI.
New app or existing app
Create a Vite app with the Svelte and TypeScript template, then let the Svelte CLI add Tailwind. The template keeps its entry in src/main.ts.
Create a Vite + Svelte app
npx create-vite@latest my-app --template svelte-tsAdd Tailwind CSS v4
npx sv add tailwindcss="plugins:none"Existing app? Run sv add tailwindcss if your stylesheet does not already start with @import "tailwindcss";.
Configuration
Declare #lib in package.json imports and mirror it in tsconfig so the Svelte CLI can validate the aliases. Then run the Svelte registry init once.
Create components.json and the theme
npx shadcn-svelte@latest init{
"imports": {
"#lib": "./src/lib/index.js",
"#lib/*": "./src/lib/*"
}
}import { svelte } from "@sveltejs/vite-plugin-svelte";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [svelte(), tailwindcss()],
});{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"paths": {
"#lib": ["./src/lib"],
"#lib/*": ["./src/lib/*"]
}
}
}{
"compilerOptions": {
"paths": {
"#lib": ["./src/lib"],
"#lib/*": ["./src/lib/*"]
}
}
}{
"tailwind": {
"css": "src/app.css",
"baseColor": "neutral"
},
"aliases": {
"components": "#lib/components",
"utils": "#lib/utils",
"ui": "#lib/components/ui",
"hooks": "#lib/hooks",
"lib": "#lib"
}
}@import "tailwindcss";Add a component
Run the Svelte CLI from the project root. It writes the dialog under src/lib/components/prequelui and installs motion and lucide-svelte.
Add the animated component
npx shadcn-svelte@latest add https://prequeluianimate.terravidhal.me/r/svelte/dialog.json<script lang="ts">
import Dialog from "#lib/components/prequelui/Dialog.svelte";
</script>
<main class="grid min-h-svh place-items-center">
<Dialog trigger="Open dialog" title="A Vite + Svelte page" />
</main>Dark mode
Set the class before the module bundle runs. Vite serves index.html first, so the first frame is already correct.
<script>const saved = localStorage.getItem("theme");const dark =saved === "dark" ||(!saved && matchMedia("(prefers-color-scheme: dark)").matches);document.documentElement.classList.toggle("dark", dark);</script>
Verification
Run the dev server, open the page and trigger the dialog. Then test the theme and reduced motion.
- The component mounts without a hydration warning.
- Both themes use the same tokens and the same durations.
- Reduced motion keeps the state change and removes the travel.
Start the dev server
npm run devMore Svelte guides
All frameworks