Skip to content

可以使用 .npmrcbunfig.toml 配置私有注冊表。雖然兩者都支持,但我們推薦使用 bunfig.toml 以獲得更高的靈活性和 Bun 特定選項。

要為特定的 npm 作用域配置注冊表:

toml
[install.scopes]
# 作為字符串
"@myorg1" = "https://usertitle:password@registry.myorg.com/"

# 作為帶有用戶名/密碼的對象
# 你可以引用環境變量
"@myorg2" = {
  username = "myusername",
  password = "$npm_pass",
  url = "https://registry.myorg.com/"
}

# 作為帶有令牌的對象
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }

你的 bunfig.toml 可以引用環境變量。Bun 會自動從 .env.local.env.[NODE_ENV].env 加載環境變量。有關更多信息,請參閱 文檔 > 環境變量

toml
[install.scopes]
"@myorg3" = { token = "$npm_token", url = "https://registry.myorg.com/" }

請參閱 文檔 > 包管理器 獲取 Bun 包管理器的完整文檔。

Bun學習網由www.bunjs.com.cn整理維護