---
title: "添加组件"
description: "使用 nimbus-docs add 从注册表安装组件、工具和功能。"
---

> Documentation Index
> Fetch the complete documentation index at: https://nimbus-docs.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加组件

`nimbus-docs add <slug>` 从[注册表](/registry)安装内容。根据你要添加的内容类型，它有两种工作模式——直接复制文件，或者通过配方交给编码智能体处理。

<h2 id="components-and-utilities">组件和工具</h2>

对于 `registry:ui` 和 `registry:lib` 类型的 slug，CLI 会解析依赖关系，将文件复制到你的仓库中，并安装所需的 npm 包：

```sh
npx add accordion
pnpm dlx add accordion
yarn dlx add accordion
bunx add accordion
```

1. **解析依赖**

   CLI 会递归遍历 slug 的 `registryDependencies` 和 npm `dependencies`。
2. **复制文件**

   每个文件会放置到其声明的路径——`src/components/ui/<slug>/`、`src/lib/` 等。
3. **注册全局组件**

   在 MDX 中使用但未导入的组件需要添加到 `src/components.ts` 中。CLI 会提示你需要添加哪些。

安装完成后，组件就存在于你的仓库中——你可以自由编辑。使用 `--yes` 跳过覆盖确认提示。

<h2 id="features">功能</h2>

对于 `registry:feature` 类型的 slug，没有文件需要复制。配方是一段 Markdown 提示词，编码智能体会读取它、适配你的项目并应用：

```sh
npx add 404-page
pnpm dlx add 404-page
yarn dlx add 404-page
bunx add 404-page
```

如果环境中检测到编码智能体，CLI 会将配方输出到 stdout 供其消费。否则你可以手动传递：

```sh
npx add 404-page --print | claude
pnpm dlx add 404-page --print | claude
yarn dlx add 404-page --print | claude
bunx add 404-page --print | claude
```

<h2 id="browse-whats-available">浏览可用内容</h2>

```sh
npx list
pnpm dlx list
yarn dlx list
bunx list
```
```sh
npx list --type ui
pnpm dlx list --type ui
yarn dlx list --type ui
bunx list --type ui
```

每个已发布的组件在 [/components](/components) 都有展示页面——包括预览、属性和安装命令。参见 [CLI](/cli) 参考文档了解所有参数选项。

Source: https://nimbus-docs.cn/adding-components/index.mdx
