Docs
命令行工具(CLI)
命令行工具(CLI)
使用命令行工具(CLI)为项目添加组件。
注意: 我们刚刚发布了新的 shadcn
命令行工具(CLI)。更多信息请参阅 更新日志 。
init
使用 init
命令为新项目初始化配置和依赖关系。
init
命令将安装依赖包、添加 cn
工具包、配置 tailwind.config.js
文件和项目的 CSS 变量。
pnpm dlx shadcn@latest init
配置 components.json
时会问你几个问题:
您想使用哪种风格? › New York
您希望使用哪种配色作为基色? › Zinc
您想为配色使用 CSS 变量吗? › no / yes
选项
用法: shadcn init [options] [components...]
初始化项目并安装依赖包
参数:
components 要添加的组件或指向组件的 url。
选项:
-d, --defaults 使用默认值,即 new-york、zinc 和 css 变量。(默认值:false)
-f, --force 强行覆盖现有的 components.json 配置文件。(默认值:false)
-y, --yes 跳过确认提示。(默认值:false)
-c, --cwd <cwd> 工作目录。默认为当前目录。
-h, --help 显示本命令的帮助信息
add
使用 add
命令为项目添加组件和依赖包。
pnpm dlx shadcn@latest add [component]
你将看到一个组件列表供你选择:
您想添加哪些组件? › 按空格键选择。按 A 键全选/全不选。
按回车键提交。
◯ accordion
◯ alert
◯ alert-dialog
◯ aspect-ratio
◯ avatar
◯ badge
◯ button
◯ calendar
◯ card
◯ checkbox
选项
用法: shadcn add [options] [components...]
为当前项目添加组件
参数:
components 要添加的组件或指向组件的 url。
Options:
-y, --yes 跳过确认提示。(默认:false)
-o, --overwrite 覆盖已有文件。(默认值:false)
-c, --cwd <cwd> 工作目录。默认为当前目录。
-a, --all 添加所有可用的组件。(默认值:false)
-p, --path <path> 放置组件的路径。
-h, --help 显示本命令的帮助信息
build
Use the build
command to generate the registry JSON files.
pnpm dlx shadcn@latest build
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
To customize the output directory, use the --output
option.
pnpm dlx shadcn@latest build --output ./public/registry