Skip to content

Bun 支持从 .npmrc 文件加载配置选项,允许你重用现有的注册表/作用域配置。

NOTE

我们建议将你的 `.npmrc` 文件迁移到 Bun 的 [`bunfig.toml`](/zh-cn/runtime/bunfig) 格式,因为它提供更 灵活的选项,并且可以让你配置 Bun 特定的选项。

支持的选项

设置默认注册表

默认注册表用于解析包,其默认值是 npm 的官方注册表(https://registry.npmjs.org/)。

要更改它,你可以在 .npmrc 中设置 registry 选项:

ini
registry=http://localhost:4873/

等效的 bunfig.toml 选项是 install.registry

toml
install.registry = "http://localhost:4873/"

为特定作用域设置注册表

@<scope>:registry 允许你为特定作用域设置注册表:

ini
@myorg:registry=http://localhost:4873/

等效的 bunfig.toml 选项是在 install.scopes 中添加键:

toml
[install.scopes]
myorg = "http://localhost:4873/"

为特定注册表配置选项

//<registry_url>/:<key>=<value> 允许你为特定注册表设置选项:

ini
# 为注册表设置认证令牌
# ${...} 是环境变量的占位符
//http://localhost:4873/:_authToken=${NPM_TOKEN}


# 或者你可以设置用户名和密码
# 注意密码是 base64 编码的
//http://localhost:4873/:username=myusername

//http://localhost:4873/:_password=${NPM_PASSWORD}

# 或者使用 _auth,它是你的用户名和密码
# 组合成单个字符串,然后进行 base 64 编码
//http://localhost:4873/:_auth=${NPM_AUTH}

支持以下选项:

  • _authToken
  • username
  • _password(base64 编码的密码)
  • _auth(base64 编码的 username:password,例如 btoa(username + ":" + password)

等效的 bunfig.toml 选项是在 install.scopes 中添加键:

toml
[install.scopes]
myorg = { url = "http://localhost:4873/", username = "myusername", password = "$NPM_PASSWORD" }

控制本地可用的工作区包如何安装:

ini
link-workspace-packages=true

等效的 bunfig.toml 选项是 install.linkWorkspacePackages

toml
[install]
linkWorkspacePackages = true

save-exact:保存精确版本

始终保存精确版本而不带 ^ 前缀:

ini
save-exact=true

等效的 bunfig.toml 选项是 install.exact

toml
[install]
exact = true

Bun学习网由www.bunjs.com.cn整理维护