背景:
npm(Nodejs) 和yarn 都是包管理器。 yarn发布于2016年10月,在github上的star已经超过了npm 。 像npm一样,yarn使用本地缓存。与npm不同的是,yarn无需互联网连接就能安装本地缓存的依赖项,它提供了离线模式。这个功能在2012年的npm项目中就被提出来过,但一直没有实现。yarn还提供了一些其他改进,例如,它允许合并项目中使用到的所有的包的许可证,这一点让人很高兴。
修改镜像源
为什么需要修改镜像源?
执行 yarn,npm各种命令的时候,默认是去npm/yarn官方(服务器在国外)镜像源获取需要安装的具体软件信息,国内有时候访问很慢,所以要将镜像源修改为阿里旗下维护的一个完整的 npm 镜像源https://registry.npm.taobao.org/ (同样适用于 yarn)
淘宝镜像以10分钟一次的频率同步官网
方式一:安装cnpm
npm install cnpm -g --registry=https://registry.npm.taobao.org
cnpm -v
测试是否安装成功
方式二:改变地址
查看当前使用的镜像源
1.yarn config get registry
2.npm config get registry
npm默认地址:https://registry.npmjs.org/
yarn默认地址:https://registry.yarnpkg.com
修改镜像源的三种方式
1. 临时修改镜像源
yarn save 软件名 --registry https://registry.npm.taobao.org/
2. 全局修改
1.yarn config set registry https://registry.npm.taobao.org/
2.npm config set registry https://registry.npm.taobao.org
3. 使用第三方软件快速修改,切换(推荐)
1.npm install -g yrm
2.npm install -g nrm
yrm ls
npm ----- https://registry.npmjs.org/
cnpm ---- http://r.cnpmjs.org/
taobao -- https://registry.npm.taobao.org/
nj ------ https://registry.nodejitsu.com/
rednpm -- http://registry.mirror.cqupt.edu.cn
skimdb -- https://skimdb.npmjs.com/registry
yarn ---- https://registry.yarnpkg.com
yrm use taobao
yrm test taobao // 测试访问速度
nrm ls