由于 npm 的源在国外,所以国内用户使用起来有很多不方便,比如拖慢下载速度。
如何使用
有很多方法来配置 npm registry 地址,下面根据不同情境列出几种比较常用的方法。以淘宝 npm 为例
更换为淘宝 npm 源
npm config set registry http://registry.npmmirror.com
|
使用 npm 官方镜像
npm config set registry https://registry.npmjs.org/
|
NPM 检查并更新项目依赖的版本
npm install -g npm-check-updates
ncu
ncu -u
npm install
|
已知的 npm 镜像源
目前国内除了淘宝(npmmirror),已知的 npm 镜像源还有:
已知的 Nodejs 预编译包:
淘宝 NPM 镜像站喊你切换新域名啦
要点总结如下:
- 淘宝 NPM 镜像站品牌升级,新品牌为 npmmirror (NPM 中国镜像站)。
- 广为人知的淘宝 NPM 镜像老域名(*.npm.taobao.org)将在 2022.06.30 号正式下线和停止 DNS 解析。
- 涉及到的域名迁移如下:
http://npm.taobao.org => http://npmmirror.com http://registry.npm.taobao.org => http://registry.npmmirror.com
|
- 可能产生的大影响:
简而言之,所有写死的都得换。
企业用户需要联系 网管 / IT/SRE 更新防火墙白名单。
存量应用的 lock 文件,开发者需要自行执行 sed 等指令去替换或重新生成。
本地 npmrc 里面的 registry 地址(如果有,则)需要开发者自行更新。
本文已经过时的内容备份
2022.02.12 移除内容
## 如何使用
有很多方法来配置npm registry地址,下面根据不同情境列出几种比较常用的方法。以淘宝npm为例
### 临时使用
``bash npm --registry https://registry.npm.taobao.org install express ``
### 持久使用
``bash npm config set registry https://registry.npm.taobao.org ``
配置后可通过下面方式来验证是否成功:
``bash npm config get registry ``
或者
``bash npm info express ``
### 更换为淘宝npm源
``bash npm install -g cnpm --registry=https://registry.npm.taobao.org ``
通过cnpm更新模块
``bash cnpm install expresstall express ``
### 使用官方镜像
``bash npm config set registry https://registry.npmjs.org/ ``
## 总结
更换为淘宝npm源
``bash npm config set registry https://registry.npm.taobao.org ``
使用官方镜像
``bash npm config set registry https://registry.npmjs.org/ ``
NPM检查并更新项目依赖的版本
``bash #### 安装 npm install -g npm-check-updates #### 检查当前目录下可更新的依赖项 ncu #### 升级 package.json ncu -u #### 根据更新的 package.json 安装新版本 npm install ``
|