你好同学,我是沐爸,欢迎点赞、收藏和关注!个人知乎、公众号"沐爸空间"
nrm (npm registry manager) 是一个 npm 源管理器,源通常就是我们说的镜像,它允许你在 npm 源之间快速切换。使用国内的镜像,可以大幅度提高安装依赖的速度。
1.全局安装
npm i -g nrm
2.查看可选源
nrm ls
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/
注:星号表示当前使用源
3.查看当前源
nrm current
=> You are using taobao registry.
4.切换源
nrm use taobao
=> SUCCESS The registry has been changed to 'taobao'.
5.添加源
nrm add <registryName> <url>
registryName 为源名称,url为源地址。比如添加一个公司私有的 npm 源,地址为 http://127.0.0.1:3000
nrm add demoNpm http://127.0.0.1:3000
=> SUCCESS Add registry demoNpm success, run nrm use demoNpm command to use demoNpm registry.
6.删除源
nrm del demoNpm
=> SUCCESS The registry 'demoNpm' has been deleted successfully.
7.测试源速度
一般情况下,taobao 的速度是最快的。
nrm test taobao
=> taobao ---- 239 ms
nrm test npm
=> npm ---- 868 ms
提示:npm 通过 nrm 配置了淘宝源后,下载速度快于 cnpm,因此推荐使用 npm。
关联文章: