因为有些包需要翻墙或者是境外的服务器,所以使用常规的 npm 安装方式有可能安装很慢或者安装失败,所以淘宝就帮我们把一些需要翻墙的包同步到了国内服务器,所以使用淘宝镜像安装速度会很快。

有几种方式:

一、只是临时使用

npm install --registry=https://registry.npm.taobao.org(多个包安装)

npm --registry https://registry.npm.taobao.org install express(单个包安装,express 为某个具体包名)

某个具体的包

二、使用 cnpm 代替 npm 安装

cnpm 是阿里默认安装包的工具,平时使用 npm install 的方式改为 cnpm install 即可

1、首先安装 cnpm

$ npm install -g cnpm --registry=https://registry.npm.taobao.org

2、检测 cnpm 版本,如果安装成功可以看到 cnpm 的基本信息。

cnpm -v

3、以后安装插件只需要使用 cnpm intall 即可

三、通过更改 npm 默认下载源的方式

假如不想更改为 cnpm 的方式,可以采用修改 npm 配置的形式

npm config set registry https://registry.npm.taobao.org/

检查是否修改成功

npm config get registry

四、恢复为默认的 npm 下载方式

npm config set registry https://registry.npmjs.org/
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐