命令行
使用 CLI 将组件添加到你的项目。
init
使用 init
命令初始化新项目的配置和依赖。
¥Use the init
command to initialize configuration and dependencies for a new project.
init
命令安装依赖、添加 cn
实用程序、配置 tailwind.config.js
和项目的 CSS 变量。
¥The init
command installs dependencies, adds the cn
util, configures tailwind.config.js
, and CSS variables for the project.
pnpm dlx shadcn@latest init
你将被问到几个问题来配置 components.json
:
¥You will be asked a few questions to configure 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
选项
¥Options
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
使用 add
命令将组件和依赖添加到你的项目中。
¥Use the add
command to add components and dependencies to your project.
pnpm dlx shadcn@latest add [component]
你将看到一个组件列表供你选择:
¥You will be presented with a list of components to choose from:
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
选项
¥Options
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.
-a, --all add all available components. (default: false)
-p, --path <path> the path to add the component to.
-h, --help display help for command
build
使用 build
命令生成注册表 JSON 文件。
¥Use the build
command to generate the registry JSON files.
pnpm dlx shadcn@latest build
此命令读取 registry.json
文件并在 public/r
目录中生成注册表 JSON 文件。
¥This command reads the registry.json
file and generates the registry JSON files in the public/r
directory.
Usage: shadcn build [options] [registry]
build components for a shadcn registry
Arguments:
registry path to registry.json file (default: "./registry.json")
Options:
-o, --output <path> destination directory for json files (default: "./public/r")
-c, --cwd <cwd> the working directory. defaults to the current directory. (default:
"/Users/shadcn/Code/shadcn/ui/packages/shadcn")
-h, --help display help for command
要自定义输出目录,请使用 --output
选项。
¥To customize the output directory, use the --output
option.
pnpm dlx shadcn@latest build --output ./public/registry