配置
pnpm 设置分为两类:
🌐 pnpm settings are divided into two categories:
-
Authentication and certificate settings are stored in INI files. These contain sensitive credentials and should not be committed to your repository. See Authentication Settings for details.
-
All other settings are stored in YAML files: the project
pnpm-workspace.yamland the globalconfig.yaml.
pnpm 也不再从 package.json 的 pnpm 字段读取设置。设置应在 pnpm-workspace.yaml 中定义。
🌐 pnpm also no longer reads settings from the pnpm field of package.json. Settings should be defined in pnpm-workspace.yaml.
本地项目配置
🌐 Local project configuration
项目级别设置放在 pnpm-workspace.yaml:
🌐 Project-level settings go in pnpm-workspace.yaml:
nodeVersion: "22"
saveExact: true
全局配置
🌐 Global configuration
全局 YAML 配置文件(config.yaml)位于以下路径之一:
🌐 The global YAML config file (config.yaml) is located at one of the following paths:
- 如果设置了 $XDG_CONFIG_HOME 环境变量,那么就是 $XDG_CONFIG_HOME/pnpm/config.yaml
- 在 Windows 上:~/AppData/Local/pnpm/config/config.yaml
- 在 macOS 上:~/Library/Preferences/pnpm/config.yaml
- 在 Linux 上:~/.config/pnpm/config.yaml
全局 rc 文件(仅用于注册表和认证设置)位于:
🌐 The global rc file (for registry and auth settings only) is at:
- 如果设置了 $XDG_CONFIG_HOME 环境变量,那么就是 $XDG_CONFIG_HOME/pnpm/rc
- 在 Windows 上:~/AppData/Local/pnpm/config/rc
- 在 macOS 上:~/Library/Preferences/pnpm/rc
- 在 Linux 上:~/.config/pnpm/rc
环境变量
🌐 Environment variables
名称以 pnpm_config_(或 PNPM_CONFIG_)开头的环境变量会被加载到配置中。这些会覆盖来自 pnpm-workspace.yaml 的设置,但不会覆盖命令行参数。
🌐 Environment variables whose names start with pnpm_config_ (or PNPM_CONFIG_) are loaded into configuration. These override settings from pnpm-workspace.yaml but not CLI arguments.
pnpm 不再读取 npm_config_* 环境变量。请改用 pnpm_config_* 环境变量(例如,使用 pnpm_config_registry 代替 npm_config_registry)。
🌐 pnpm no longer reads npm_config_* environment variables. Use pnpm_config_* environment variables instead (e.g., pnpm_config_registry instead of npm_config_registry).
例如:
🌐 For example:
pnpm_config_save_exact=true pnpm add foo
如果你需要 pnpm 在多个硬盘或文件系统上工作,请阅读 [常见问题解答]。
🌐 If you need pnpm to work across multiple hard drives or filesystems, please read the FAQ.
有关管理配置的更多信息,请参阅 [config 命令]。
🌐 See the config command for more information on managing configuration.