Capítulo 9 de 108
Three ways to get shadcn/ui into a Next.js project: visually via shadcn/create preset builder, directly scaffolded via the CLI, or manually wired into an existing project.
/create?template=next; generates npx shadcn@latest init --preset [CODE] --template next.init -t next: CLI-only scaffold with interactive prompts (base, preset, monorepo).--monorepo: flag for monorepo scaffolding; then run add with -c apps/web to target the workspace.create-next-app (or manual Tailwind setup) plus a @/* alias in tsconfig.json before running plain npx shadcn@latest init.--src-dir: places app in src/app and points @/* to ./src/*.# Preset or CLI scaffold
npx shadcn@latest init --preset [CODE] --template next
npx shadcn@latest init -t next
npx shadcn@latest init -t next --monorepo
# Existing project
npx create-next-app@latest --src-dir
npx shadcn@latest init
# Add + use a component
npx shadcn@latest add card
npx shadcn@latest add card -c apps/web # monorepo
import { Button } from "@/components/ui/button"
export default function Home() {
return (
<div className="flex min-h-svh items-center justify-center">
<Button>Click me</Button>
</div>
)
}
add no App Router.| Path | tsconfig alias | Import example |
|---|---|---|
Recommended create-next-app defaults | @/* → ./* | @/components/ui/card |
--src-dir | @/* → ./src/* | src/app/page.tsx imports same alias |
| Monorepo | workspace-scoped | @workspace/ui/components/card |
init without Tailwind/@/* alias configured: for manual/older projects, set up Tailwind and the tsconfig.json paths alias first.-c apps/web (or run from that dir) on every add, and import from @workspace/ui/components/* instead of @/components/ui/*.init/add CLI commands.--src-dir changes both the file location and the tsconfig alias target, keep them in sync.init/add command reference.init actually writes.