Docs
CLI
CLI
使用命令行(CLI)向您的项目添加组件。
Note: We just released a new shadcn
CLI. See the changelog for more information.
init
使用 ini
命令初始化新项目的配置和依赖。
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...]
初始化您的项目并安装依赖项
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
命令向您的项目添加组件和依赖。
npx shadcn@latest add [component]
您将看到一个组件列表供选择:
您希望添加哪些组件? › 空格选择。A 切换全部。
输入以提交
◯ accordion
◯ alert
◯ alert-dialog
◯ aspect-ratio
◯ avatar
◯ badge
◯ button
◯ calendar
◯ card
◯ checkbox
选项
Usage: shadcn add [options] [components...]
向您的项目添加一个组件
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
Monorepo
In a monorepo, you can specify the path to your workspace with the -c
or --cwd
option.
npx shadcn@latest init -c ./apps/www
or
npx shadcn@latest add alert-dialog -c ./apps/www