配置
pnpm 设置分为两类:
- Registry and auth settings are stored in INI files: the global
rcfile and local.npmrcfiles. - pnpm-specific settings are stored in YAML files: the global
config.yamland the localpnpm-workspace.yaml.
pnpm 不再从 rc 文件中读取非身份验证和非注册表设置。 Other settings must be defined in pnpm-workspace.yaml or the global config.yaml.
pnpm also no longer reads settings from the pnpm field of package.json. Settings should be defined in pnpm-workspace.yaml.
本地项目配置
Project-level settings go in pnpm-workspace.yaml:
pnpm-workspace.yaml
nodeVersion: "22"
saveExact: true
全局配置
The global YAML config file (config.yaml) is located at one of the following paths:
- If the $XDG_CONFIG_HOME env variable is set, then $XDG_CONFIG_HOME/pnpm/config.yaml
- On Windows: ~/AppData/Local/pnpm/config/config.yaml
- On macOS: ~/Library/Preferences/pnpm/config.yaml
- On Linux: ~/.config/pnpm/config.yaml
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 whose names start with pnpm_config_ are loaded into configuration. These override settings from pnpm-workspace.yaml but not CLI arguments.
示例:
pnpm_config_save_exact=true pnpm add foo
如果你需要 pnpm 跨多个硬盘或文件系统工作, 请阅读常见问题解答。
See the config command for more information on managing configuration.