跳到主内容
版本:11 & 12

设置(pnpm-workspace.yaml)

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

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

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

相关配置文件为:

注意

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

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

警告

Since v11.5.3, env variables are not expanded in settings of pnpm-workspace.yaml that define registry URLs: registry and the URL values of registries and namedRegistries. 在这些设置中,包含 ${...} 占位符的值会被忽略。 由于 pnpm-workspace.yaml 会被提交到仓库中,如果注册源 URL 中包含可展开的环境变量,恶意仓库可能会利用这一点,将环境中的敏感信息泄露给攻击者控制的注册源。 改为在受信任的位置配置动态注册源 URL:全局配置文件或 CLI 选项。

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 →

锁文件设置

Full reference →

网络设置

Full reference →

请求设置

Full reference →

对等依赖设置

Full reference →

命令行设置

Full reference →

Node.js 设置

Full reference →

构建设置

Full reference →

Versioning Settings

Full reference →

其它设置

Full reference →

Workspace Settings

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

Full reference →

Settings documented elsewhere