> ## Documentation Index
> Fetch the complete documentation index at: https://bun.zhcndoc.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 添加可选依赖

要将 npm 包作为可选依赖添加，请使用 `--optional` 标志。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun add zod --optional
```

***

这将把该包添加到 `package.json` 的 `optionalDependencies` 中。

```json package.json icon="file-json" theme={"theme":{"light":"github-light","dark":"dracula"}}
{
  "optionalDependencies": {
    "zod": "^3.0.0" // [!code ++]
  }
}
```

***

完整的 Bun 包管理器文档请参见 [文档 > 包管理器](/pm/cli/install)。
