.npmrc 文件加载配置选项,允许你重用现有的 registry/作用域配置。
我们建议将你的
.npmrc 文件迁移到 Bun 的 bunfig.toml 格式,因为它提供了更灵活的选项,并且可以让你配置 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 编码的用户名:密码,例如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:
.npmrc
node-linker:
node-linker 选项控制安装模式。Bun 支持 pnpm 和 yarn 两者的值:
| 值 | 描述 | 接受者 |
|---|---|---|
isolated | 符号链接结构,带有隔离依赖 | pnpm |
hoisted | 扁平 node_modules 结构 | pnpm |
pnpm | 符号链接结构(等同于 isolated) | yarn |
node-modules | 扁平 node_modules 结构(等同于 hoisted) | yarn |
.npmrc
public-hoist-pattern 和 hoist-pattern: 控制托举
控制哪些包被托举到根节点的 node_modules:
.npmrc