文档
CLI

CLI

使用 CLI 将组件添加到您的项目中。

初始化

使用 init 命令初始化新项目的配置和依赖项。

The init 命令安装依赖项,添加 cn 工具,配置 tailwind.config.js 以及项目的 CSS 变量。

npx shadcn@latest init

系统将询问您一些问题,以配置 components.json

Which style would you like to use? › New York
Which color would you like to use as base color? › Zinc
Do you want to use CSS variables for colors? › no / yes

选项

Usage: shadcn init [options] [components...]

initialize your project and install dependencies

Arguments:
  components         the components to add or a url to the component.

Options:
  -d, --defaults    use default values i.e new-york, zinc and css variables. (default: false)
  -f, --force       force overwrite of existing components.json. (default: false)
  -y, --yes         skip confirmation prompt. (default: false)
  -c, --cwd <cwd>   the working directory. defaults to the current directory.
  -h, --help       display help for command

添加

使用 add 命令将组件和依赖项添加到您的项目中。

npx shadcn@latest add [component]

系统将向您展示一个要选择的组件列表。

Which components would you like to add? › Space to select. A to toggle all.
Enter to submit.

◯  accordion
◯  alert
◯  alert-dialog
◯  aspect-ratio
◯  avatar
◯  badge
◯  button
◯  calendar
◯  card
◯  checkbox

选项

Usage: shadcn add [options] [components...]

add a component to your project

Arguments:
  components         the components to add or a url to the component.

Options:
  -y, --yes          skip confirmation prompt. (default: false)
  -o, --overwrite    overwrite existing files. (default: false)
  -c, --cwd <cwd>    the working directory. defaults to the current directory.
  -p, --path <path>  the path to add the component to.
  -h, --help         display help for command

单仓库

在单仓库中,您可以使用 -c--cwd 选项指定工作区路径。

npx shadcn@latest init -c ./apps/www

npx shadcn@latest add alert-dialog -c ./apps/www