.npmrc 文件中加载配置选项,因此你可以复用现有的注册表和作用域配置。
配置按以下顺序加载,后面的来源会覆盖前面的来源:
~/.npmrc(或$XDG_CONFIG_HOME/.npmrc)./.npmrcbunfig.toml(全局,然后项目)BUN_CONFIG_REGISTRY/NPM_CONFIG_REGISTRY和BUN_CONFIG_TOKEN/NPM_CONFIG_TOKEN环境变量--registry等命令行标志
.npmrc 中的凭据(//<registry>/:_authToken 等)会根据主机和路径与 registry 进行匹配,即使 registry URL 本身是在 bunfig.toml 中设置的
值可以引用环境变量:${NAME} 会被替换为该变量的值(如果未设置则保持原样),而 ${NAME?} 在未设置时会变为空字符串
我们建议将你的
.npmrc 文件迁移到 Bun 的 bunfig.toml 格式,该格式支持更多选项,包括 Bun 专属选项。支持的选项
设置默认的 registry
Bun 从默认 registry 中解析软件包,该 registry 是npm 的官方 registry(https://registry.npmjs.org/)。
要更改它,请在 .npmrc 中设置 registry 选项:
.npmrc
bunfig.toml 选项是 install.registry:
bunfig.toml
为特定作用域设置 registry
@<scope>:registry 为特定作用域设置 registry:
.npmrc
bunfig.toml 选项是在 install.scopes 中添加一个键:
bunfig.toml
配置特定 registry 的选项
//<registry_url>/:<key>=<value> 为特定 registry 设置选项:
.npmrc
_authTokenusername_password(经过 base64 编码的密码)_auth(经过 base64 编码的 username:password,例如btoa(username + ":" + password))email
bunfig.toml 选项是在 install.scopes 中添加一个键:
bunfig.toml
link-workspace-packages:控制工作区包的安装
控制本地可用时工作区包的安装方式:
.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
ca 和 cafile:配置 CA 证书
为 registry 连接配置自定义 CA 证书:
.npmrc
omit 和 include:控制依赖类型
控制安装哪些依赖类型:
.npmrc
dev,peer,optional
install-strategy 和 node-linker:安装策略
控制软件包在 node_modules 中的布局方式。为了兼容其他包管理器,Bun 同时接受 npm 的 install-strategy 和 pnpm/yarn 的 node-linker。有关托举布局和隔离布局的差异,请参阅隔离安装。
npm 的 install-strategy:
.npmrc
node-linker:
node-linker 控制安装模式。Bun 接受来自 pnpm 和 yarn 的值:
.npmrc
public-hoist-pattern 和 hoist-pattern:控制托举
控制哪些包被托举到根节点的 node_modules:
.npmrc