NPM使用淘宝镜像的方法

说明

npm源在国外,所以国内访问很慢,甚至很多依赖是无法安装的,所以使用国内淘宝源会方便很多,做个记录。

步骤

有很多方法来配置npm的registry地址,下面根据不同情境列出几种比较常用的方法。

临时使用

注意:原来的https://registry.npm.taobao.org已弃用

1
npm --registry https://registry.npmmirror.com install express

永久使用

1
npm config set registry https://registry.npmmirror.com

使用cnpm

1
npm install -g cnpm --registry=https://registry.npmmirror.com

cnpm是淘宝官方定制的一个命令行工具,支持除了publish之外的所有命令,使用时仅需要将npm替换为cnpm即可,但实际使用情况不佳,经常会出现很多莫名其妙的问题,不太建议使用

恢复默认

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

检测方法

查看源设置(两个命令都可以)

1
2
3
npm config get registry

npm info express
使用 Hugo 构建
主题 StackJimmy 设计