npm--加快下载速度的方法

原文网址:npm--加快下载速度的方法_IT利刃出鞘的博客-CSDN博客

简介

说明

        本文介绍解决npm下载速度很慢的方法。

        npm默认从npm官网(国外网站)下载模块,下载速度特别慢。

解决方法

1.使用国内镜像
2.使用cnpm(淘宝的国内npm工具)

法1:国内镜像(推荐)

法1:直接配置,以后不需加--registry参数

npm config set registry http://registry.npmmirror.com

验证是否配置成功:

npm config get registry

法2:安装包时指定镜像地址

npm install xxx --registry http://registry.npmmirror.com

国内镜像大全

  1. 淘宝
    1. NPM镜像-NPM下载地址-NPM安装教程-阿里巴巴开源镜像站
    2. 旧镜像:http://registry.npm.taobao.org,2022年6月30日改为了:http://registry.npmmirror.com

法2:cnpm(不推荐)

不建议使用cnpm,因为有各种奇怪的问题。

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

以后就可以直接使用cnpm代替npm。

或者直接通过添加 npm 参数 alias 一个新命令:

alias cnpm="npm --registry=https://registry.npm.taobao.org \
--cache=$HOME/.npm/.cache/cnpm \
--disturl=https://npm.taobao.org/dist \
--userconfig=$HOME/.cnpmrc"

# Or alias it in .bashrc or .zshrc
$ echo '\n#alias for cnpm\nalias cnpm="npm --registry=https://registry.npm.taobao.org \
  --cache=$HOME/.npm/.cache/cnpm \
  --disturl=https://npm.taobao.org/dist \
  --userconfig=$HOME/.cnpmrc"' >> ~/.zshrc && source ~/.zshrc

猜你喜欢

转载自blog.csdn.net/feiying0canglang/article/details/126054955
今日推荐