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

# 生成兼容 yarn 的锁文件

<Note>
  Bun v1.1.39 引入了 `bun.lock`，一种 JSONC 格式的锁文件。`bun.lock` 易于阅读且在无需任何配置的情况下可通过 git 进行差异比较，
  同时不会影响性能。在 1.2.0 及更高版本中，它是新项目默认使用的格式。[**了解更多。**](/pm/lockfile#text-based-lockfile)
</Note>

***

使用 `--yarn` 参数可生成一个兼容 Yarn 的 `yarn.lock` 文件（同时生成 `bun.lock{b}`）。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun install --yarn
```

***

要将此设置为默认行为，请在你的 `bunfig.toml` 文件中添加如下内容。

```toml bunfig.toml icon="settings" theme={"theme":{"light":"github-light","dark":"dracula"}}
[install.lockfile]
print = "yarn"
```

***

若想将 Yarn 锁文件打印到控制台而不写入磁盘，可以使用 `bun` “运行”你的 `bun.lockb`。

```sh terminal icon="terminal" theme={"theme":{"light":"github-light","dark":"dracula"}}
bun bun.lockb
```

```txt theme={"theme":{"light":"github-light","dark":"dracula"}}
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1
# bun ./bun.lockb --hash: 9BFBF11D86084AAB-9418b03ff880c569-390CE6459EACEC9A...

abab@^2.0.6:
  version "2.0.6"
  resolved "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz"
  integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvH...
```

***

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