npm与yarn命令对比
npm | yarn |
---|---|
npm init | yarn init |
npm init -y | yarn init -y |
npm install | yarn |
npm install xxx | yarn add xxx |
npm install --global xxx | yarn global add xxx |
npm install xxx --save | yarn add xxx |
npm install xxx --save-dev | yarn add xxx --dev |
npm install xxx@版本号 | yarn add xxx@版本号 |
npm uninstall xxx | yarn remove xxx |
npm update --save | yarn upgrade |
npm run | yarn run |
npm run xxx | yarn run xxx |
npm run dev | yarn dev |
镜像源
原淘宝npm域名已停止解析
https://npm.taobao.org 和 https://registry.npm.taobao.org 在 2022.06.30 号正式下线和停止 DNS 解析。
旧域名 | 新域名 |
---|---|
https://npm.taobao.org | https://npmmirror.com |
https://registry.npm.taobao.org | https://registry.npmmirror.com |
yarn
安装yarn
npm install -g yarn
卸载yarn
npm uninstall yarn -g
yarn依赖
// yarn 安装依赖
yarn add 包名 // 局部安装
yarn global add 包名 // 全局安装
// yarn 卸载依赖
yarn remove 包名 // 局部卸载
yarn global remove 包名 // 全局卸载(如果安装时安到了全局,那么卸载就要对应卸载全局的)
// yarn 查看全局安装过的包
yarn global list
yarn全局安装位置
yarn的命令目录bin与其全局安装位置保持同一根目录
// 查看yarn的命令目录
yarn global bin // 地址为 E:\installationPath\nodejs\node_global\bin
// 查看yarn的全局安装目录
yarn global dir // 地址为:C:\Users\ll\AppData\Local\Yarn\Data\global
// 修改yarn的全局安装位置和缓存位置
yarn config set global-folder "E:\installationPath\yarn\global"
yarn config set cache-folder "E:\installationPath\yarn\cache"
配置源:
npm | yarn | |
---|---|---|
查看配置 | npm config list | yarn config list |
查询源 | npm config get registry | yarn config get registry |
更换国内源 | npm config set registry https://registry.npmmirror.com | yarn config set registry https://registry.npmmirror.com |
恢复官方源 | npm config set registry https://registry.npmjs.org | yarn config set registry https://registry.yarnpkg.com |
删除注册表 | npm config delete registry | yarn config delete registry |
关于yarn create quasar报文件名、目录名或卷标语法不正确
参考:https://juejin.cn/post/7045178655454003208
NVM
参见:使用nvm管理node多版本(安装、卸载nvm,配置环境变量,更换npm淘宝镜像)
npm install 安装依赖包 --save、–save-dev、-S、-D的区别
参见:https://blog.csdn.net/aaqingying/article/details/101371352
npm install
默认npm install --save
npm install --save
等于npm install -S
:写入dependencies
中,开发阶段和生产阶段都需要。
npm install --save-dev
等于npm install -D
:写入devDependencies
中,只在开发阶段需要。
未完待续…