Appearance
node npmrc 设置镜像源
优先级
项目根目录的 .npmrc 的配置,优先级最高,且随着项目一起,可以免去因不同开发者的电脑的环境配置不同而导致的依赖下载异常的问题;实际开发中也推荐在根目录下配置一份,可以给每个项目配置不同的镜像,项目之间的配置互不影响。
bash
# 配置 npm 的默认镜像源为淘宝镜像源
registry = "https://registry.npm.taobao.org"
# 配置此项目的局部镜像源之 electron
electron_mirror = "https://npm.taobao.org/mirrors/electron/"
# 配置此项目的局部镜像源之 sass
# node-sass 现在很少有项目用了,主要用来兼容一些老旧项目
sass_binary_site= "https://npm.taobao.org/mirrors/node-sass/"
# node 版本与 package.json 配置不同的时候,中断命令执行
engine-strict = true
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
常用镜像源
bash
# 淘宝镜像源
https://registry.npmmirror.com
https://registry.npm.taobao.org
# 腾讯云镜像源
http://mirrors.cloud.tencent.com/npm/
# 华为云镜像源
https://mirrors.huaweicloud.com/repository/npm/
# 官方默认全局镜像
https://registry.npmjs.org
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
注意事项
- yarn 会读取.npmrc 的配置文件,所以不必为 yarn 再设置一次
- 删除
.npmrc文件,即可恢复默认配置 - 项目根目录命令行
npm config get registry查看是否设置成功