Settings (.npmrc)
pnpm gets its configuration from the command line, environment variables, and
.npmrc files.
The pnpm config command can be used to update and edit the contents of the
user and global .npmrc files.
四個相關的檔案是:
- per-project configuration file (/path/to/my/project/.npmrc)
- per-workspace configuration file (the directory that contains the
pnpm-workspace.yamlfile)
- per-user configuration file (~/.npmrc)
- global configuration file (/etc/npmrc)
All .npmrc files are an INI-formatted list of key = value parameters.
Values in the .npmrc files may contain env variables using the ${NAME} syntax. 您也可以使用預設值來指定環境變數。 Using ${NAME-fallback} will return fallback if NAME isn't set. ${NAME:-fallback} will return fallback if NAME isn't set, or is an empty string.
相依性提升設定
hoist
- Default: true
- Type: boolean
When true, all dependencies are hoisted to node_modules/.pnpm/node_modules. This makes
unlisted dependencies accessible to all packages inside node_modules.
hoist-workspace-packages
- Default: true
- Type: boolean
When true, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules or to <workspace_root>/node_modules depending on other hoisting settings (hoist-pattern and public-hoist-pattern).
hoist-pattern
- Default: ['*']
- Type: string[]
Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules. 預設情況下,所有套件都會提升,但是如果你知道只有一些有缺陷套件有幻影依賴關係, 您可以使用此選項來只提升有幻影依賴關係的套件 (推薦)。
例如:
hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*
You may also exclude patterns from hoisting using !.
例如:
hoist-pattern[]=*types*
hoist-pattern[]=!@types/react
public-hoist-pattern
- Default: []
- Type: string[]
Unlike hoist-pattern, which hoists dependencies to a hidden modules directory
inside the virtual store, public-hoist-pattern hoists dependencies matching
the pattern to the root modules directory. 提升至根模組目錄表示應用程式程式碼將可以存取虛設的相依性,即使這個程式碼對解決方案策略進行了不當的修改也一樣。
在處理一些不當解析相依性的錯誤可插入式工具時,這個設定很有用。
例如:
public-hoist-pattern[]=*plugin*
Note: Setting shamefully-hoist to true is the same as setting
public-hoist-pattern to *.
You may also exclude patterns from hoisting using !.
例如:
public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react
shamefully-hoist
- 預設值:false
- 型別:布林值
By default, pnpm creates a semistrict node_modules, meaning dependencies have
access to undeclared dependencies but modules outside of node_modules do not.
使用此頁面配置,生態系統中的大多數套件將沒有問題的運作。
However, if some tooling only works when the hoisted dependencies are in the
root of node_modules, you can set this to true to hoist them for you.