npm代理设置 + npm配置镜像源

npm代理设置

输入以下几行命令:

npm config rm proxy
npm config rm http-proxy
npm config rm https-proxy
npm config set registry http://cmc-cd-mirror.rnd.huawei.com/npm
npm config set strict-ssl=false

set registry可以换为国内的其他开源镜像仓,比如阿里的,百度的,淘宝的

npm配置镜像源 (以配置华为镜像源为例)

要配置华为镜像源,首先需要设置 npm 使用华为的镜像站点。华为的 npm 镜像站点可以显著提高下载速度,特别是在中国大陆地区。你可以按照以下步骤进行配置:

配置华为 npm 镜像源

 1.设置镜像源为华为的镜像站点: 打开终端(命令行工具),执行以下命令来将 npm 的镜像源设置为华为的 npm 镜像:

npm config set registry https://mirrors.huaweicloud.com/repository/npm/

2. 验证镜像源是否设置成功: 设置完成后,可以运行以下命令确认当前的 npm 镜像源: 

npm config get registry

 如果输出是 https://mirrors.huaweicloud.com/repository/npm/,则说明已经成功设置。

3. 清除缓存并重新安装依赖: 为确保缓存和依赖是从新的镜像源安装,可以清除 npm 缓存并重新安装项目依赖:

npm cache clean --force
npm install

其他配置(可选)

  • 恢复默认 npm 镜像源: 如果你想恢复为官方的 npm 镜像源,可以执行以下命令:

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

检查 npm 配置: 如果需要查看或修改 npm 配置文件,可以使用以下命令查看所有配置项: 

npm config list

总结

通过配置华为镜像源,你应该能显著提高 npm 安装速度,尤其是在国内环境下。

你可能感兴趣的:(前端Vue,npm,前端,node.js)