使用nrm管理npm仓库

引言:

目前遇到了这样的问题: 因为个人和公司的npm仓库环境不一样,导致使用时需要频繁的切换npm指向。
所以,为了提高工作效率,就采用了nrm的方式来管理多个npm仓库。

老规矩,先举一个🌰。
For,example:
当前有两个仓库指向,分别是:
公司私有仓库:http://公司仓库IP/repository/npm-public/
淘宝镜像仓库:https://registry.npmmirror.com/
因为不同仓库的依赖不同,所以需要在不同场景使用不同的仓库指向。
针对这个问题:

传统操作:

一、通过命令直接切换Npm指向

// 第一步, 先查询当前的仓库指向
npm config get registry
// 第二步, 切换需要的仓库指向
// 如
npm config set registry http://公司仓库IP/repository/npm-public/
// 或者
https://registry.npmmirror.com/

二、在具体项目内指定依赖安装所依赖的仓库

// 进入项目的依赖安装目录级
// 如
npm install --registry=http://公司仓库IP/repository/npm-public/
// 或者
npm install --registry=https://registry.npmmirror.com/

以上两种方式存在两个问题:
1、你每次都 需要复制仓库地址 并设置一下仓库指向
2、当你的npm仓库个数过多,你需要去记录所有npm仓库


三、通过.npmrc 文件进行管理

// #开头表示注释, 具体根据需要把当前项目使用的npm仓库放开,把不需要的仓库#注释
#registry=https://registry.npmmirror.com/
registry=http://公司仓库IP/repository/npm-public/

这种方式较之上面两种要好,但是需要每个项目设置一个.npmrc管理仓库指向

通过nrm管理:

安装nrm

npm install -g nrm // 全局安装nrm

添加一个仓库至nrm

// 如添加一个名为company[公司]的npm仓库
nrm add company http://公司仓库IP/repository/npm-public/   

从nrm中删除一个仓库

// 删除一个名为test-del的npm仓库
nrm add company test-del

修改一个仓库的名称

// 如 仓库test名称 修改为 test1
nrm rename test test1

查询当前的所有npm仓库

// 查看仓库列表
nrm ls

// 命令反馈
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
  taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/
  company ------ http://公司仓库IP/repository/npm-public/
  official ----- https://registry.npmjs.org/

切换当前仓库指向

// 切换当前使用仓库为taobao 
nrm use taobao

// 命令反馈
  npm ---------- https://registry.npmjs.org/
  yarn --------- https://registry.yarnpkg.com/
  tencent ------ https://mirrors.cloud.tencent.com/npm/
  cnpm --------- https://r.cnpmjs.org/
* taobao ------- https://registry.npmmirror.com/
  npmMirror ---- https://skimdb.npmjs.com/registry/
  company ------ http://公司仓库IP/repository/npm-public/
  official ----- https://registry.npmjs.org/

测试一个仓库的响应速度

nrm test company // 测试命令  npm test <registryName>

npm ------ 688ms // 被测试仓库的响应速度输出为688ms

测试所有仓库源的响应速度

nrm test // 测试命令  默认查询全部

  // 测试反馈 Fetch Error 表示连接失败
  
  npm ------ Fetch Error
  yarn ----- 799ms
  tencent -- 79ms
  cnpm ----- 2909ms
* taobao --- 282ms
  npmMirror - 1363ms
  company -- 688ms
  official - Fetch Error

其他的一些命令,可以通过nrm -h来挨个查看

Commands:
  ls                                      List all the registries
  current [options]                       Show current registry name or URL
  use <registry>                          Change registry to registry
  add <registry> <url> [home]             Add one custom registry
  login [options] <registryName> [value]  Set authorize information for a custom registry with a base64 encoded string or username and pasword
  set-hosted-repo <registry> <value>      Set hosted npm repository for a custom registry to publish packages
  set-scope <scopeName> <value>           Associating a scope with a registry
  del-scope <scopeName>                   Remove a scope
  set [options] <registryName>            Set custom registry attribute
  rename <registryName> <newName>         Set custom registry name
  del <registry>                          Delete one custom registry
  home <registry> [browser]               Open the homepage of registry with optional browser
  publish [options] [<tarball>|<folder>]  Publish package to current registry if current registry is a custom registry.
   if you're not using custom registry, this command will run npm publish directly
  test [registry]                         Show response time for specific or all registries
  help                                    Print this help
   if you want to clear the NRM configuration when uninstall you can execute "npm uninstall nrm -g -C or npm uninstall nrm -g --clean"


以上,
*就是本次的全部内容,如果能够帮助到你, 麻烦给个小赞支持一下~~~~~*

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
引用:nrm是一个可以帮助您管理npm注册表的工具。您可以使用nrm来轻松地切换不同的npm镜像源。在您的项目目录中添加.yarnrc文件并在其中写入`registry "http://your.registry"`,或者在HOME目录的.yarnrc文件中进行配置来安装nrm。通过运行`npm install -g nrm`命令来安装nrm。然后,您可以运行`nrm ls`命令来查看可用的npm注册表列表。 问题:请告诉我,npm nrm -g是什么意思? npm nrm -g是一条命令,用于全局安装nrm工具,以便您可以在命令行中使用nrm管理npm注册表。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [nrmNPM注册表管理器,可以在不同的注册表之间快速切换:npm,cnpm,nj,淘宝](https://download.csdn.net/download/weixin_42097914/15008241)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [npm换源成淘宝镜像](https://blog.csdn.net/qq_42306443/article/details/103210285)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

penn.ji

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值