❤ 使用npm 淘宝镜像(更新与2024-06-11)
1、最新镜像地址 2024-06-11
# 查看npm版本
npm -v
# 查看npm镜像地址
npm config get registry
# 设置为国内的镜像
//切换新源
npm config set registry https://registry.npmmirror.com
# 官方最新迁移镜像地址 (永久替换 2021-04-18 留言)
(永久替换 2024-06-11 留言---下面的地址是官方稳定长期版本)
npm config set registry http://registry.npmmirror.com
(1)NPM概念
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种:
- 允许用户从NPM服务器下载别人编写的第三方包到本地使用。
- 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
- 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。
(2)常用命令
使用npm时网络环境较差,所以备用
2-1 常用命令
# 检测npm安装的版本号
npm -v
# 查询当前镜像源
npm get registry
# 清空缓存
npm cache clean --force
# 删除项目下的node_modules文件夹
npm uninstall
# 安装依赖
npm install
# 忽略依赖安装
npm install with --force
# 忽略依赖冲突安装
npm install --legacy-peer-deps
2-2 查看本地npm配置的仓库镜像
npm get registry
# 查询当前镜像源
npm config get registry
2-3 旧版本的npm通过npm命令来升级
npm install npm -g
2-4 设置为淘宝镜像(废弃)
- 设置本次从淘宝镜像上安装的包不改变npm原有的仓库镜像源 (单次npm使用淘宝镜像)
npm install --registry=
- 设置为淘宝镜像 (废弃)
npm config set registry http:///
设置回默认的官方镜像 (废弃)
npm config set registry https:///
设置electron淘宝镜像
npm config set ELECTRON_MIRROR "/mirrors/electron/"
查看和删除electron淘宝镜像设置:
npm config get ELECTRON_MIRROR
npm config delete ELECTRON_MIRROR
2-5 配置本地npm的仓库镜像源地址,以后下载包,在下载命令中不配置镜像源时,就从上述配置的镜像源中下载指定的安装包
npm config set registry <https://....仓库镜像源地址>
registry = https://registry.npm.taobao.org
2-6 使用cnpm命令替换npm命令
npm install -g cnpm --registry=https://registry.npm.taobao.org
cnpm install npm@7.18.1 -g // 利用cnpm安装指定版本
(3)npm 使用
3-1 查看所有全局安装的包
npm -g list
3-2 卸载某个包;卸载所有的包
npm uninstall <包名> ; npm uninstall *
3-3 查看依赖包
npm ls
3-4 清除缓存
npm cache verify
或者
npm cache clean --force