Перейти до основного вмісту
Версія: 11 & 12

Налаштування (pnpm-workspace.yaml)

pnpm отримує налаштування з командного рядка, змінних середовища та файлу pnpm-workspace.yaml.

З файлів .npmrc зчитуються лише налаштування автентифікації та реєстру. Усі інші налаштування (наприклад, hoistPattern, nodeLinker, shamefullyHoist тощо) мають бути налаштовані у pnpm-workspace.yaml або глобальному файлі ~/.config/pnpm/config.yaml.

Команду pnpm config можна використовувати для читання та редагування вмісту файлів проєкту та файлів глобальної конфігурації.

Відповідні конфігураційні файли:

примітка

Налаштування, пов'язані з авторизацією, обробляються через .npmrc.

Значення у файлах конфігурації можуть містити змінні env із використанням синтаксису ${NAME}. Змінні env також можуть бути вказані зі стандартними значеннями. Використання ${NAME-fallback} поверне fallback, якщо NAME не задано. ${NAME:-fallback} поверне fallback, якщо NAME не задано або є порожнім рядком.

попередження

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. Values containing a ${...} placeholder in these settings are ignored. 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. Because pnpm-workspace.yaml is committed to the repository, expanding env variables in registry URLs could be exploited by a malicious repository to leak secrets from the environment to an attacker-controlled registry. Configure dynamic registry URLs in a trusted location instead: the global configuration file or CLI options.

примітка

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. Докладніше див. у Каталоги.

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 →

Параметри модулів

Full reference →

Налаштування підйому залежностей

Full reference →

Налаштування сховища

Full reference →

Параметри Lockfile

Full reference →

Налаштування мережі

Full reference →

Налаштування запиту

Full reference →

Параметри прямих залежностей

Full reference →

Параметри CLI

Full reference →

Параметри Node.js

Full reference →

Параметри збирання

Full reference →

Versioning Settings

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.

Full reference →

Settings documented elsewhere