npm registry
1、Global registry
我们可以通过设置 npm 或者 pnpm 的 config 来设置 Global Registry,例如:
# npm npm config set registry=http://localhost:2000 # or pnpm pnpm config set registry=http://localhost:2000
这样一来,在代码层面就可以通过 process.env.npm_config_registry 读取到这里的配置。
2、npmrc
无论是 npm 或 pnpm 默认都会从项目的 .npmrc 文件中读取配置,所以当我们需要包的发布要走私有 Registry 的时候,可以这样设置:
registry = http://localhost:2000
3、--registry
在执行 npm publish 或 pnpm publish 的时候,我们也可以通过带上 --registry Option 来告知对应的包管理工具要发布的 Registry,例如:
# npm npm publish --registry=http://localhost:2000 # or pnpm pnpm publish --registry=http://localhost:2000
4、PublishConfig
PublishConfig指的是我们可以在要执行 publish 命令的项目 package.json 中的 publishConfig.registry 来告知 npm 或 pnpm 要发布的 Registry,例如:
{ ... "publishConfig": { "registry": "http://localhost:2000" } ... }
转自:https://mp.weixin.qq.com/s/MYLi4mSgoi5KXj4-_OgT3A

浙公网安备 33010602011771号