设置(pnpm-workspace.yaml)

pnpm 从命令行、环境变量和 pnpm-workspace.yaml 获取配置。

仅从 .npmrc 文件中读取身份验证和注册表设置。所有其他设置(例如 hoistPattern、nodeLinker、shamefullyHoist 等)必须在 pnpm-workspace.yaml 或全局的 ~/.config/pnpm/config.yaml 中进行配置。

pnpm config 命令可用于读取和编辑项目和全局配置文件的内容。

相关配置文件为:

注意

授权相关的设置通过 .npmrc 处理。

配置文件中的值可能包含使用 ${NAME} 语法的环境变量。也可以使用默认值指定环境变量。使用 ${NAME-fallback} 将在未设置 NAME 时返回 fallback。 ${NAME:-fallback} ,会在 NAME 不存在或为空字符串时返回 fallback 。

警告

自 v11.5.3 版本起,pnpm-workspace.yaml 中定义镜像源 URL 的设置项——即 registry 以及 registries 和 namedRegistries 中的 URL 值——将不再进行环境变量展开。在这些设置中,包含 ${...} 占位符的值会被忽略。 In the registry declaration shape of registries (since v11.23.0), the URL is the key rather than the value, and the same rule applies to the keys. 由于 pnpm-workspace.yaml 会被提交到仓库中,如果注册源 URL 中包含可展开的环境变量,恶意仓库可能会利用这一点,将环境中的敏感信息泄露给攻击者控制的注册源。改为在受信任的位置配置动态注册源 URL:全局配置文件或 CLI 选项。

注意

Since v11.22.0, a project's pnpm-workspace.yaml cannot choose where pnpm keeps its credentials, its own installation, or other machine-level state: bin, configDir, dir, globalBinDir, globalDir, npmrcAuthFile, pnpmHomeDir, stateDir, userconfig, and workspaceDir are ignored there, with a warning. Set them in the global configuration file or on the command line instead. cacheDir and storeDir are unaffected.

packages#

Besides settings, pnpm-workspace.yaml defines the root of the workspace and enables you to include / exclude directories from the workspace. If the packages field is omitted, only the root package is included in the workspace.

例如:

pnpm-workspace.yaml
packages:
  # 指定根目录直接子目录中的包
  - 'my-app'
  # packages/ 直接子目录中的所有包
  - 'packages/*'
  # components/ 子目录中的所有包
  - 'components/**'
  # 排除测试目录中的包
  - '!**/test/**'

即使使用了自定义目录位置通配符,根软件包也总是被包含.

目录也在 pnpm-workspace.yaml 文件中定义。有关详细信息,请参阅 Catalogs。

pnpm-workspace.yaml
packages:
  - 'packages/*'

catalog:
  chalk: ^4.1.2

catalogs:
  react16:
    react: ^16.7.0
    react-dom: ^16.7.0
  react17:
    react: ^17.10.0
    react-dom: ^17.10.0

packageConfigs#

添加于:v11.0.0

允许为各个工作区包设置项目特定的配置。这将替换工作区项目特定的 .npmrc 文件。

packageConfigs 可以指定为包名称到配置对象的映射:

pnpm-workspace.yaml
packages:
  - "packages/project-1"
  - "packages/project-2"
packageConfigs:
  "project-1":
    saveExact: true
  "project-2":
    savePrefix: "~"

或者作为模式匹配规则的数组:

pnpm-workspace.yaml
packages:
  - "packages/project-1"
  - "packages/project-2"
packageConfigs:
  - match: ["project-1", "project-2"]
    modulesDir: "node_modules"
    saveExact: true

设置#

Every setting is listed below, grouped by topic. Follow a setting to read its documentation, or open the full reference of a group.

依赖解析#

Full reference →

Node 模块设置#

Full reference →

依赖提升设置#

完整参考 →

存储设置#

完整参考 →

锁文件设置#

完整参考 →

网络设置#

完整参考 →

请求设置#

完整参考 →

对等依赖设置#

Full reference →

命令行设置#

Full reference →

Node.js 设置#

Full reference →

构建设置#

Full reference →

版本设置#

完整参考 →

其它设置#

完整参考 →

工作空间设置#

These settings are configured in pnpm-workspace.yaml as well, but are documented together with the workspace feature they belong to.

完整参考 →

Settings documented elsewhere#