> ## 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.

# bun link

> 链接本地包以便开发

在本地目录中使用 `bun link` 来注册当前包为“可链接”包。

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
cd /path/to/cool-pkg
cat package.json
bun link
```

```txt theme={"theme":{"light":"github-light","dark":"dracula"}}
bun link v1.3.3 (7416672e)
成功！已注册 "cool-pkg"

要在项目中使用 cool-pkg，请运行：
  bun link cool-pkg

或者在你的 package.json 文件的依赖中添加：
  "cool-pkg": "link:cool-pkg"
```

现在可以使用 `bun link cool-pkg` 将此包“链接”到其他项目中。这将在目标项目的 `node_modules` 目录中创建一个符号链接，指向本地目录。

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
cd /path/to/my-app
bun link cool-pkg
```

此外，可以使用 `--save` 标志将 `cool-pkg` 添加到你的应用的 package.json 的 `dependencies` 字段中，使用一个特殊的版本说明符，告诉 Bun 从已注册的本地目录加载，而不是从 `npm` 安装：

```json package.json icon="file-json" theme={"theme":{"light":"github-light","dark":"dracula"}}
{
  "name": "my-app",
  "version": "1.0.0",
  "dependencies": {
    "cool-pkg": "link:cool-pkg" // [!code ++]
  }
}
```

## 取消链接

在包的根目录使用 `bun unlink` 来注销本地包。

```bash terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
cd /path/to/cool-pkg
bun unlink
```

```txt theme={"theme":{"light":"github-light","dark":"dracula"}}
bun unlink v1.3.3 (7416672e)
```

***

# CLI 使用方法

```bash theme={"theme":{"light":"github-light","dark":"dracula"}}
bun link <packages>
```

### 安装范围

<ParamField path="--global" type="boolean">
  全局安装。别名：<code>-g</code>
</ParamField>

### 依赖管理

<ParamField path="--production" type="boolean">
  不安装 devDependencies。别名：<code>-p</code>
</ParamField>

<ParamField path="--omit" type="string">
  从安装中排除 <code>dev</code>、<code>optional</code> 或 <code>peer</code> 依赖
</ParamField>

### 项目文件及锁文件

<ParamField path="--yarn" type="boolean">
  写入 <code>yarn.lock</code> 文件（yarn v1）。别名：<code>-y</code>
</ParamField>

<ParamField path="--frozen-lockfile" type="boolean">
  禁止更改锁文件
</ParamField>

<ParamField path="--save-text-lockfile" type="boolean">
  保存文本格式的锁文件
</ParamField>

<ParamField path="--lockfile-only" type="boolean">
  仅生成锁文件，不安装依赖
</ParamField>

<ParamField path="--no-save" type="boolean">
  不更新 <code>package.json</code> 或保存锁文件
</ParamField>

<ParamField path="--save" type="boolean" default="true">
  保存到 <code>package.json</code>（默认启用）
</ParamField>

<ParamField path="--trust" type="boolean">
  添加到项目 <code>package.json</code> 的 <code>trustedDependencies</code> 并安装该包
</ParamField>

### 安装控制

<ParamField path="--force" type="boolean">
  始终从注册表请求最新版本并重新安装所有依赖。别名：<code>-f</code>
</ParamField>

<ParamField path="--no-verify" type="boolean">
  跳过验证新下载包的完整性
</ParamField>

<ParamField path="--backend" type="string" default="clonefile">
  针对平台优化依赖安装。可选值：<code>clonefile</code>（默认）、<code>hardlink</code>、<code>symlink</code>、<code>copyfile</code>
</ParamField>

<ParamField path="--linker" type="string">
  链接策略（可选 <code>isolated</code> 或 <code>hoisted</code>）
</ParamField>

<ParamField path="--dry-run" type="boolean">
  不执行任何安装
</ParamField>

<ParamField path="--ignore-scripts" type="boolean">
  跳过项目 <code>package.json</code> 中的生命周期脚本（依赖的脚本永远不会运行）
</ParamField>

### 网络与注册表

<ParamField path="--ca" type="string">
  提供证书颁发机构的签名证书
</ParamField>

<ParamField path="--cafile" type="string">
  同 <code>--ca</code>，但是为证书的文件路径
</ParamField>

<ParamField path="--registry" type="string">
  默认使用特定注册表，覆盖 <code>.npmrc</code>、<code>bunfig.toml</code> 和环境变量
</ParamField>

<ParamField path="--network-concurrency" type="number" default="48">
  最大并发网络请求数量（默认 48）
</ParamField>

### 性能与资源

<ParamField path="--concurrent-scripts" type="number" default="5">
  生命周期脚本最大并发作业数（默认 5）
</ParamField>

### 缓存

<ParamField path="--cache-dir" type="string">
  从指定目录路径存储和加载缓存数据
</ParamField>

<ParamField path="--no-cache" type="boolean">
  完全忽略清单缓存
</ParamField>

### 输出与日志

<ParamField path="--silent" type="boolean">
  不输出任何日志
</ParamField>

<ParamField path="--quiet" type="boolean">
  打包时只显示压缩包名称
</ParamField>

<ParamField path="--verbose" type="boolean">
  超级详细的日志输出
</ParamField>

<ParamField path="--no-progress" type="boolean">
  禁用进度条
</ParamField>

<ParamField path="--no-summary" type="boolean">
  不打印总结信息
</ParamField>

### 平台目标

<ParamField path="--cpu" type="string">
  为可选依赖覆盖 CPU 架构（例如，<code>x64</code>、<code>arm64</code>、<code>\*</code> 表示全部）
</ParamField>

<ParamField path="--os" type="string">
  为可选依赖覆盖操作系统（例如，<code>linux</code>、<code>darwin</code>、<code>\*</code> 表示全部）
</ParamField>

### 全局配置与上下文

<ParamField path="--config" type="string">
  指定配置文件路径（<code>bunfig.toml</code>）。别名：<code>-c</code>
</ParamField>

<ParamField path="--cwd" type="string">
  设置特定的当前工作目录
</ParamField>

### 帮助

<ParamField path="--help" type="boolean">
  打印此帮助菜单。别名：<code>-h</code>
</ParamField>
