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}支持以下選項:
_authTokenusername_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" }link-workspace-packages:控制工作區包安裝
控制本地可用的工作區包如何安裝:
ini
link-workspace-packages=true等效的 bunfig.toml 選項是 install.linkWorkspacePackages:
toml
[install]
linkWorkspacePackages = truesave-exact:保存精確版本
始終保存精確版本而不帶 ^ 前綴:
ini
save-exact=true等效的 bunfig.toml 選項是 install.exact:
toml
[install]
exact = true