因为npm的服务器位于国外可能会影响安装,所以淘宝团队创建了国内镜像。淘宝镜像与官方同步频率目前为10分钟一次,以保证尽量与官方服务同步。
使用的话一种是通过配置淘宝源使用,另一种就是使用cnpm安装,下面依次介绍。
永久使用需要配置源。
1 | npm config set registry https://registry.npm.taobao.org |
1 | npm config get registry |
之后再使用npm安装时就是走的淘宝的源了。
1 | npm config set registry https://registry.npmjs.org |
临时使用的话参照下面格式即可。
1 | npm install -g XXX --registry=https://registry.npm.taobao.org |
使用淘宝源安装cnpm,然后直接使用cnpm安装扩展。
1 | npm install cnpm -g --registry=https://registry.npm.taobao.org |
1 | cnpm -v |
1 | cnpm install xxx |