Auth & Registry Settings (.npmrc)
The settings on this page must be configured via .npmrc files. pnpm uses the npm CLI under the hood for publishing, so these settings need to be in a format that npm can read.
For details on how .npmrc files are loaded, see the pnpm config command.
For settings that can be configured in pnpm-workspace.yaml, see Settings (pnpm-workspace.yaml).
Registry Settings
registry
- 預設值:https://registry.npmjs.org/
- 類型:url
npm 套件登錄的基底 URL (包含斜線)。
@jsr:registry
新增於 v10.9.0
- Default: https://npm.jsr.io/
- 類型:url
The base URL of the JSR package registry.
<scope>:registry
應該用於指定范圍套件的 npm 登錄。 例如,設定 @babel:registry=https://example.com/packages/npm/ 將會在您使用 pnpm add @babel/core 或任何, or any @babel 的有限范圍套件時,強制從 https://example.com/packages/npm 擷取套件,而不是從預設登錄擷取。
Authentication Settings
<URL>:_authToken
Define the authentication bearer token to use when accessing the specified registry. 例如:
//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
您也可以使用環境變量。 例如:
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
或者您也可以完全不變更 .npmrc,而直接使用環境變量。
npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
<URL>:tokenHelper
A token helper is an executable which outputs an auth token. This can be used in situations where the authToken is not a constant value but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token.
The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is only permitted to set this value in the user .npmrc. Otherwise a project could place a value in a project's local .npmrc and run arbitrary executables.
Setting a token helper for the default registry:
tokenHelper=/home/ivan/token-generator
Setting a token helper for the specified registry:
//registry.corp.com:tokenHelper=/home/ivan/token-generator
Proxy Settings
https-proxy
- 預設值:null
- 類型:url
A proxy to use for outgoing HTTPS requests. If the HTTPS_PROXY, https_proxy, HTTP_PROXY or http_proxy environment variables are set, their values will be used instead.
If your proxy URL contains a username and password, make sure to URL-encode them. 例如:
https-proxy=https://use%21r:pas%2As@my.proxy:1234/foo
Do not encode the colon (:) between the username and password.
http-proxy
proxy
- 預設值:null
- 類型:url
這是用於外寄 HTTP 要求的 Proxy。 If the HTTP_PROXY or http_proxy environment variables are set, proxy settings will be honored by the underlying request library.
local-address
- Default: undefined
- Type: IP Address
The IP address of the local interface to use when making connections to the npm registry.
maxsockets
- Default: networkConcurrency x 3
- 類型:Number
The maximum number of connections to use per origin (protocol/host/port combination).
noproxy
- 預設值:null
- Type: String
A comma-separated string of domain extensions that a proxy should not be used for.
SSL Settings
strict-ssl
- 預設值:true
- 類型:Boolean
Whether or not to do SSL key validation when making requests to the registry via HTTPS.
See also the ca option.
Certificate Settings
ca
- 預設值:npm CA 憑證
- 類型:String (字符串)、陣列或 null
The Certificate Authority signing certificate that is trusted for SSL connections to the registry. 值應採用 PEM 格式 (也就是「Base-64 編碼的 X.509 (.CER)」)。 例如:
ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
Set to null to only allow known registrars, or to a specific CA cert to trust only that specific signing authority.
Multiple CAs can be trusted by specifying an array of certificates:
ca[]="..."
ca[]="..."
另參見 strict-ssl 設定。
cafile
- 預設值:null
- 類型:path
A path to a file containing one or multiple Certificate Authority signing certificates. Similar to the ca setting, but allows for multiple CAs, as well as for the CA information to be stored in a file instead of being specified via CLI.
<URL>:cafile
Define the path to a Certificate Authority file to use when accessing the specified registry. 例如:
//registry.npmjs.org/:cafile=ca-cert.pem
<URL>:ca
Added in: v10.25.0
Define an inline Certificate Authority certificate for the specified registry. The value must be PEM-encoded, like the global ca setting, but it only applies to the matching registry URL.
//registry.example.com/:ca=-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----
cert
- 預設值:null
- Type: String
A client certificate to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). 範例:
cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"
It is not the path to a certificate file.
<URL>:cert
Added in: v10.25.0
Define an inline client certificate to use when accessing the specified registry. 例如:
//registry.example.com/:cert=-----BEGIN CERTIFICATE-----...-----END CERTIFICATE-----
<URL>:certfile
Define the path to a certificate file to use when accessing the specified registry. 範例:
//registry.npmjs.org/:certfile=server-cert.pem
key
- 預設值:null
- Type: String
A client key to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). 範例:
key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"
It is not the path to a key file. Use <URL>:keyfile if you need to reference the file system instead of inlining the key.
This setting contains sensitive information. Don't write it to a local .npmrc file committed to the repository.
<URL>:key
Added in: v10.25.0
Define an inline client key for the specified registry URL.
//registry.example.com/:key=-----BEGIN PRIVATE KEY-----...-----END PRIVATE KEY-----
<URL>:keyfile
Define the path to a client key file to use when accessing the specified registry. 範例:
//registry.npmjs.org/:keyfile=server-key.pem