Vite
Install shadcn/ui in a Vite React app with the official CLI. Tailwind v4, the @ alias, then add a component from the shadcn.io registry.
init -t vite scaffolds the app. For a repo you already have: Tailwind, both tsconfigs, vite.config.ts, then init. Then add from the shadcn.io registry.
Use the CLI
Add a component
npx shadcn@latest add https://www.shadcn.io/r/card.jsonMonorepo: from apps/web, or -c apps/web from the root.
Import it
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card"
function App() {
return (
<Card className="max-w-sm">
<CardHeader>
<CardTitle>Project Overview</CardTitle>
<CardDescription>
Track progress and recent activity for your Vite app.
</CardDescription>
</CardHeader>
<CardContent>
Your design system is ready. Start building your next component.
</CardContent>
</Card>
)
}
export default AppMonorepo: apps/web/src/App.tsx, import @workspace/ui/components/card.
Existing project
Create the app if you need one
React + TypeScript template. Skip if the repo exists.
npm create vite@latestTailwind CSS
Skip if it is already there.
npm install tailwindcss @tailwindcss/viteReplace src/index.css:
@import "tailwindcss";tsconfig.json
Vite splits TypeScript config. Put baseUrl and paths on both tsconfig.json and tsconfig.app.json.
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}vite.config.ts
npm install -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 init
npx shadcn@latest initAdd a component
npx shadcn@latest add https://www.shadcn.io/r/button.jsonimport { 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 AppThe @ import still fails
Vite needs the alias in vite.config.ts. The editor needs it in tsconfig.app.json. One file is not enough.
Questions
Related
Was this page helpful?
Sign in to leave feedback.