Skip to content

1.npm设置镜像

bash
-- 查看 npm 安装目录
npm root -g
 
-- 查看 npm 配置信息
npm config list
 
-- 安装 cnpm 命令(国内淘宝源) - 可以使用 cnpm 替代绝大多数 npm 指令
npm install -g cnpm --registry=https://registry.npm.taobao.org #这里是临时使用镜像下载,必须加这个后缀,否则下载不下来
-- 版本检测
cnpm -v
 
-- 或者仅修改 npm 命令镜像
-- 设置为淘宝镜像
npm config set registry https://registry.npm.taobao.org
-- 修改为官方镜像
npm config set registry https://registry.npmjs.org/
-- 查询当前镜像配置
npm get registry

问题:npm换了镜像还是安装很慢?

我们使用cnpm重新下载npm即可!

bash
cnpm i -g npm@8.16.0

但是有的时候在vscode里面还是不会很快,可以使用cnpm i等!

2.yarn下载与设置镜像

bash
-- yarn (安装速度快,并行下载,缓存机制,本地缓存,可以断网使用)
npm install yarn -g
 
-- 设置淘宝镜像
yarn config set registry https://registry.npm.taobao.org
-- 设置为官方镜像
yarn config set registry https://registry.yarnpkg.com
-- 查询镜像配置
yarn config get registry

在使用yarn安装依赖包时报错,提示信息:error An unexpected error occurred: "https://registry.yarnpkg.com/killable/-/killable-1.0.0.tgz: connect ETIMEDOUT 104.16.19.35:443"

这是由于资源地址请求超时造成的,更换一下请求地址即可。

解决方案:

运行命令,把资源地址设置成npm淘宝源

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

npm config set disturl https://npm.taobao.org/dist

yarn config set registry https://registry.npm.taobao.org

3.yarn启动react项目

yarn start

yarn build

npm呢?

npm start

npm run build