110k

Vite

为 Vite 安装和配置 shadcn/ui。

创建项目

运行 init 命令来创建一个新的 Vite 项目或设置一个现有项目:

pnpm dlx shadcn@latest init -t vite

对于 monorepo 项目,使用 --monorepo 标志:

pnpm dlx shadcn@latest init -t vite --monorepo

添加组件

现在你可以开始向项目中添加组件了。

pnpm dlx shadcn@latest add button

上述命令会将 Button 组件添加到你的项目中。然后你可以这样导入它:

src/App.tsx
import { Button } from "@/components/ui/button"
 
export default function Home() {
  return (
    <div>
      <Button>点击我</Button>
    </div>
  )
}