npm 和 yarn 常用指令解读和比较
安装 npm 和 yarn
- 先安装node.js
- win+R 打开 cmd 验证 npm 的安装是否成功
npm -v //返回版本号,即为成功
- npm 成功,执行
npm install -g yarn //全局安装yarn
yarn -v //验证yarn是否成功
npm、yarn 常用命令比较:
作用 | npm | Yarn |
---|---|---|
安装 | npm install(i) | yarn |
卸载 | npm uninstall(un) | yarn remove |
全局安装 | npm install xxx –-global(-g) | yarn global add xxx |
安装包 | npm install xxx –save(-S) | yarn add xxx |
开发模式安装包 | npm install xxx –save-dev(-D) | yarn add xxx –dev(-D) |
更新 | npm update –save | yarn upgrade |
全局更新 | npm update –global | yarn global upgrade |
卸载 | pm uninstall [–save/–save-dev] | yarn remove xx |
清除缓存 | npm cache clean | yarn cache clean |
重装 | rm -rf node_modules && npm install | yarn upgrade |
npm 不常用命令解读
- 安装淘宝镜像(很常用)
npm install -g cnpm --registry=https://registry.npm.taobao.org
- 恢复镜像
npm config delete registry
//or
npm config edit(手动删除)
- 安装指定版本依赖
npm install xxx@1.x
- 查看某个模块的版本号
npm list xxx
yarn 不常用命令解读
- 验证 node_modules 中已安装的文件没有被移除
yarn install --check-files
- 重新拉取所有包,即使之前已经安装的
yarn install --force
- 不执行项目 package.json 及其依赖定义的任何脚本(比较重要,vue 项目有时会用到)
yarn install --ignore-scripts
- 不生成 yarn.lock 文件
yarn install --pure-lockfile
- 不生成 yarn.lock 文件,并且,如果需要更新则报错
yarn install --frozen-lockfile
- 当与对应包的校验不一致时, 更新 yarn.lock 文件和已安的依赖装包
yarn install --update-checksums
- 重新拉取所有包,即使之前已经安装的
yarn install --force
小技巧
鼠标右键桌面,再按键盘 s,试试,快速启动 Git Bash
End
指令用的熟练,打开项目都带风。
code . 走起