.npmrc
這是 rush init 為 monorepo .npmrc 檔案產生的範本
common/config/rush/.npmrc
# Rush uses this file to configure the NPM package registry during installation. It is applicable
# to PNPM, NPM, and Yarn package managers. It is used by operations such as "rush install",
# "rush update", and the "install-run.js" scripts.
#
# NOTE: The "rush publish" command uses .npmrc-publish instead.
#
# Before invoking the package manager, Rush will copy this file to the folder where installation
# is performed. The copied file will omit any config lines that reference environment variables
# that are undefined in that session; this avoids problems that would otherwise result due to
# a missing variable being replaced by an empty string.
#
# * * * SECURITY WARNING * * *
#
# It is NOT recommended to store authentication tokens in a text file on a lab machine, because
# other unrelated processes may be able to read the file. Also, the file may persist indefinitely,
# for example if the machine loses power. A safer practice is to pass the token via an
# environment variable, which can be referenced from .npmrc using ${} expansion. For example:
#
# //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN}
#
registry=https://registry.npmjs.org/
always-auth=false
.npmrc 檔案優先順序
一般 Rush 操作會執行下列查閱
- 為了支援不尋常的情況,NPM 組態環境變數的優先順序高於任何 .npmrc 設定。環境變數名稱的前綴為
npm_config_
。例如,設定npm_config_registry
變數會覆寫 .npmrc 中的registry
設定。NPM 的設計也接受非標準名稱模式,例如npm_config_@example:registry
。 - 通常,設定來自 Rush 複製到操作工作目錄的暫時性 .npmrc 檔案。該檔案是從 common/config/rush/.npmrc 複製而來,但會省略任何參考未定義環境變數的行(如上所述)。對於大多數操作,工作目錄將會是 common/temp。
- 如果套件管理員無法透過 1 或 2 找到設定,則會查詢使用者的 ~/.npmrc。個別使用者通常會將其驗證權杖儲存在此檔案中。
上述規則也適用於協助程式腳本,例如 install-run.js。
rush publish
指令使用不同的檔案 .npmrc-publish,並有其自身的規則。詳情請參閱此文件。
如果直接叫用套件管理員(而不是透過 Rush),則上述規則不適用。例如,如果從 shell 叫用 npm publish
,則會改為適用套件管理員的常用優先順序。一般而言,在 Rush 儲存庫中不建議這樣做,但如果使用,您可能需要建立額外的 .npmrc 檔案。