跳到主内容
版本:Next

配置

pnpm 设置分为两类:

  • 身份验证和证书设置 存储在 INI 文件中。 这些文件包含敏感凭据,不应提交到你的仓库。 参阅 身份验证设置 了解详情。
  • All other settings are stored in YAML files: the project pnpm-workspace.yaml and 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:

  • 如果设置了 $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

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 no longer reads npm_config_* environment variables. Use pnpm_config_* environment variables instead (e.g., pnpm_config_registry instead of npm_config_registry).

示例:

pnpm_config_save_exact=true pnpm add foo

如果你需要 pnpm 跨多个硬盘或文件系统工作, 请阅读 常见问题解答

有关管理配置的更多信息,请参阅 配置 命令