Back to InstallationYou are on Vite + Svelte.
Installation

Vite + Svelte

A plain Vite app with the same Svelte items and the same reduced-motion branch.

SvelteSingle-page appsSvelte 5 and TypeScript, with #lib mapped to src/lib.

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-ts
npmthe default on every machine

Add Tailwind CSS v4

npx sv add tailwindcss="plugins:none"
npmthe default on every machine

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
npmthe default on every machine
package.json
{
  "imports": {
    "#lib": "./src/lib/index.js",
    "#lib/*": "./src/lib/*"
  }
}
vite.config.ts
import { svelte } from "@sveltejs/vite-plugin-svelte";
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [svelte(), tailwindcss()],
});
tsconfig.json
{
  "files": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ],
  "compilerOptions": {
    "paths": {
      "#lib": ["./src/lib"],
      "#lib/*": ["./src/lib/*"]
    }
  }
}
tsconfig.app.json
{
  "compilerOptions": {
    "paths": {
      "#lib": ["./src/lib"],
      "#lib/*": ["./src/lib/*"]
    }
  }
}
components.json
{
  "tailwind": {
    "css": "src/app.css",
    "baseColor": "neutral"
  },
  "aliases": {
    "components": "#lib/components",
    "utils": "#lib/utils",
    "ui": "#lib/components/ui",
    "hooks": "#lib/hooks",
    "lib": "#lib"
  }
}
src/app.css
@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
npmthe default on every machine
src/App.svelte
<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.

index.html
<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 dev
npmthe default on every machine

More Svelte guides

All frameworks

Built by Vidhal. The source is available on GitHub.

MIT licensed