Vite
Install shadcn.io in a Vite project.
Use the shadcn.io preset
Initialize a Vite project with the shadcn.io registry preset.
Use the CLI
Scaffold a new Vite project directly from the terminal.
Existing Project
Configure shadcn.io manually in an existing Vite project.
Use the shadcn.io Preset
Create Project
Run the init command with the shadcn.io preset and the Vite template:
bunx --bun shadcn@latest init https://kit.dev/r/style.json -t vitepnpm dlx shadcn@latest init https://kit.dev/r/style.json -t vitenpx shadcn@latest init https://kit.dev/r/style.json -t viteyarn shadcn@latest init https://kit.dev/r/style.json -t viteAdd Components
You can add components with the CLI or copy them manually from the component docs:
- CLI: Run
npx shadcn@latest add https://kit.dev/r/<component>.json(e.g.button,dialog). - Manual: Copy component source from Manual tab in the component docs.
For example, add the Button component to your project:
bunx --bun shadcn@latest add https://kit.dev/r/button.jsonpnpm dlx shadcn@latest add https://kit.dev/r/button.jsonnpx shadcn@latest add https://kit.dev/r/button.jsonyarn shadcn@latest add https://kit.dev/r/button.jsonYou can also install every component at once:
bunx --bun shadcn@latest add https://kit.dev/r/ui.jsonpnpm dlx shadcn@latest add https://kit.dev/r/ui.jsonnpx shadcn@latest add https://kit.dev/r/ui.jsonyarn shadcn@latest add https://kit.dev/r/ui.jsonThen import and use components like this:
import { Button } from "@/components/ui/button";
function App() {
return (
<div className="flex min-h-svh flex-col items-center justify-center">
<Button>Click me</Button>
</div>
);
}
export default App;Use the CLI
Create Project
Run the init command to scaffold a new Vite project and configure shadcn.io:
bunx --bun shadcn@latest init https://kit.dev/r/style.json -t vitepnpm dlx shadcn@latest init https://kit.dev/r/style.json -t vitenpx shadcn@latest init https://kit.dev/r/style.json -t viteyarn shadcn@latest init https://kit.dev/r/style.json -t viteFor a monorepo project, use the --monorepo flag:
bunx --bun shadcn@latest init https://kit.dev/r/style.json -t vite --monorepopnpm dlx shadcn@latest init https://kit.dev/r/style.json -t vite --monoreponpx shadcn@latest init https://kit.dev/r/style.json -t vite --monorepoyarn shadcn@latest init https://kit.dev/r/style.json -t vite --monorepoAdd Components
You can add components with the CLI or copy them manually from the component docs:
- CLI: Run
npx shadcn@latest add https://kit.dev/r/<component>.json(e.g.button,dialog). - Manual: Copy component source from Manual tab in the component docs.
For example, add the Button component to your project:
bunx --bun shadcn@latest add https://kit.dev/r/button.jsonpnpm dlx shadcn@latest add https://kit.dev/r/button.jsonnpx shadcn@latest add https://kit.dev/r/button.jsonyarn shadcn@latest add https://kit.dev/r/button.jsonIf you created a monorepo, run the command from apps/web or specify the workspace from the repo root:
bunx --bun shadcn@latest add https://kit.dev/r/button.json -c apps/webpnpm dlx shadcn@latest add https://kit.dev/r/button.json -c apps/webnpx shadcn@latest add https://kit.dev/r/button.json -c apps/webyarn shadcn@latest add https://kit.dev/r/button.json -c apps/webYou can also install every component at once:
bunx --bun shadcn@latest add https://kit.dev/r/ui.jsonpnpm dlx shadcn@latest add https://kit.dev/r/ui.jsonnpx shadcn@latest add https://kit.dev/r/ui.jsonyarn shadcn@latest add https://kit.dev/r/ui.jsonThen import and use components like this:
import { Button } from "@/components/ui/button";
function App() {
return (
<div className="flex min-h-svh flex-col items-center justify-center">
<Button>Click me</Button>
</div>
);
}
export default App;If you created a monorepo, update apps/web/src/App.tsx and import from your workspace UI package instead.
Existing Project
Create Project
If you need a new Vite project, create one first and select the React + TypeScript template. Otherwise, skip this step.
bun create vite@latestpnpm create vite@latestnpm create vite@latestyarn create vite@latestAdd Tailwind CSS
If your project already has Tailwind CSS configured, skip this step.
bun add tailwindcss @tailwindcss/vitepnpm add tailwindcss @tailwindcss/vitenpm install tailwindcss @tailwindcss/viteyarn add tailwindcss @tailwindcss/viteReplace everything in src/index.css with the following:
@import "tailwindcss";Edit tsconfig.json
Vite splits TypeScript config across multiple files. Add baseUrl and paths to the compilerOptions in both tsconfig.json and tsconfig.app.json:
{
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Edit tsconfig.app.json
Add the same path resolution so your IDE resolves imports correctly:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}Update vite.config.ts
Add the path alias so Vite resolves @/ at build time:
bun add -D @types/nodepnpm add -D @types/nodenpm install -D @types/nodeyarn add -D @types/nodeimport path from "path"
import tailwindcss from "@tailwindcss/vite"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})Run the CLI
Run the shadcn init command with the shadcn.io preset to set up your project.
bunx --bun shadcn@latest init https://kit.dev/r/style.jsonpnpm dlx shadcn@latest init https://kit.dev/r/style.jsonnpx shadcn@latest init https://kit.dev/r/style.jsonyarn shadcn@latest init https://kit.dev/r/style.jsonAdd Components
You can add components with the CLI or copy them manually from the component docs:
- CLI: Run
npx shadcn@latest add https://kit.dev/r/<component>.json(e.g.button,dialog). - Manual: Copy component source from Manual tab in the component docs.
For example, add the Button component to your project:
bunx --bun shadcn@latest add https://kit.dev/r/button.jsonpnpm dlx shadcn@latest add https://kit.dev/r/button.jsonnpx shadcn@latest add https://kit.dev/r/button.jsonyarn shadcn@latest add https://kit.dev/r/button.jsonYou can also install every component at once:
bunx --bun shadcn@latest add https://kit.dev/r/ui.jsonpnpm dlx shadcn@latest add https://kit.dev/r/ui.jsonnpx shadcn@latest add https://kit.dev/r/ui.jsonyarn shadcn@latest add https://kit.dev/r/ui.jsonThen import and use components like this:
import { Button } from "@/components/ui/button";
function App() {
return (
<div className="flex min-h-svh flex-col items-center justify-center">
<Button>Click me</Button>
</div>
);
}
export default App;