包管理工具
npm
概念:npm
是node.js
自带的包管理工具(安装node
以后即可使用),可以方便地安装、升级、卸载依赖包,还可以发布自己的包到npm
仓库。
安装 node
以后:
shell
# 检查node版本
node -v
# 检查npm版本
npm -v
设置npm
为国内淘宝镜像:
shell
# 查看当前镜像源
npm config get registry
# 设置为淘宝镜像
npm config set registry https://registry.npmmirror.com
# 切换回 npm 源
npm config set registry https://registry.npmjs.org/
# 清除缓存
npm cache clean --force
pnpm
概念:pnpm
由npm/yarn
衍生而来,解决了npm/yarn
内部潜在的 bug,极大的优化了性能,扩展了使用场景。被誉为“最先进的包管理工具”。
shell
# 安装pnpm
npm i pnpm -g
# 检查版本
pnpm -v
# 查看pnpm镜像源
pnpm config get registry
# pnpm设置淘宝镜像源
pnpm config set registry https://registry.npmmirror.com
# 安装依赖
pnpm i
# 启动项目
pnpm serve / pnpm dev
cnpm
概念:cnpm
是中国npm
镜像的客户端。
shell
# 安装cnpm
npm install cnpm -g
# 检查cnpm版本
cnpm -v
# 国内安装中国镜像
npm install cnpm -g --registry=https://registry.npmmirror.com
yarn
概念:yarn
是 Facebook
推出的包管理工具,具有速度快、缓存机制好等优点。与 NPM
相比,yarn
可以更快地下载依赖包,并且支持离线模式。
yarn
常见命令:
shell
# 安装yarn
npm i -g yarn
# 查看yarn镜像源
yarn config get registry
# 设置yarn的淘宝镜像
yarn config set registry https://registry.npm.taobao.org
# yarn 安装 node_nodules
yarn install
# yarn添加依赖
yarn add [package]
# yarn卸载依赖
yarn remove [package]