Skip to main content
Bun 从 .npmrc 文件加载配置选项,因此你可以重用现有的注册表和作用域配置。
我们建议将你的 .npmrc 文件迁移为 Bun 的 bunfig.toml 格式,它支持更多选项,包括 Bun 特定的选项。

支持的选项

设置默认注册表

Bun 从默认注册表解析包,即 npm 的官方注册表(https://registry.npmjs.org/)。 要更改它,请在 .npmrc 中设置 registry 选项:
.npmrc
等效的 bunfig.toml 选项是 install.registry
bunfig.toml

为特定作用域设置注册表

@<scope>:registry 为特定作用域设置注册表:
.npmrc
等效的 bunfig.toml 选项是在 install.scopes 中添加一个键:
bunfig.toml

为特定注册表配置选项

//<registry_url>/:<key>=<value> 为特定注册表设置选项:
.npmrc
支持以下选项:
  • _authToken
  • username
  • _password(base64 编码的密码)
  • _auth(base64 编码的 username:password,例如 btoa(username + ":" + password)
  • email
等效的 bunfig.toml 选项是在 install.scopes 中添加一个键:
bunfig.toml
控制当本地可用时如何安装工作空间包:
.npmrc
等效的 bunfig.toml 选项是 install.linkWorkspacePackages
bunfig.toml

save-exact:保存精确版本

始终保存精确版本,不添加 ^ 前缀:
.npmrc
等效的 bunfig.toml 选项是 install.exact
bunfig.toml

ignore-scripts:跳过生命周期脚本

阻止在安装期间运行生命周期脚本:
.npmrc
这等效于在 bun install 中使用 --ignore-scripts 标志。

dry-run:预览更改而不安装

显示将要安装的内容而不实际安装任何东西:
.npmrc
等效的 bunfig.toml 选项是 install.dryRun
bunfig.toml

cache:配置缓存目录

设置缓存目录路径,或禁用缓存:
.npmrc
等效的 bunfig.toml 选项是 install.cache
bunfig.toml

cacafile:配置 CA 证书

为注册表连接配置自定义 CA 证书:
.npmrc

omitinclude:控制依赖类型

控制安装哪些依赖类型:
.npmrc
有效值:devpeeroptional

install-strategynode-linker:安装策略

控制包在 node_modules 中的布局方式。为了与其他包管理器兼容,Bun 同时接受 npm 的 install-strategy 和 pnpm/yarn 的 node-linker。请参阅隔离安装了解提升布局和隔离布局的区别。 npm 的 install-strategy
.npmrc
pnpm/yarn 的 node-linker node-linker 控制安装模式。Bun 同时接受 pnpm 和 yarn 的值:
.npmrc

public-hoist-patternhoist-pattern:控制提升

控制哪些包被提升到根 node_modules
.npmrc