npm+yarn用法(詳細篇)
## node
### 安裝 node
安裝(推薦:LTS)
> https://nodejs.org/en/
查詢版本
> node -v
> npm -v
### nvm
> https://github.com/coreybutler/nvm-windows
列出可安裝 node 版本
> nvm list available
安裝指定的版本(例如:16.13.0)
> nvm install 版本號
列出已安裝的版本
> nvm list
使用指定的版本(例如:16.13.0)
> nvm use 版本號
## npm
> ~/.npmrc
### 修改 npm 環(huán)境變量
D:\Program Files\nodejs
> 創(chuàng)建 2 個文件夾 node_global 和 node_cache
執(zhí)行命令
> npm config set prefix "D:\Program Files\nodejs\node_global"
> npm config set cache "D:\Program Files\nodejs\node_cache"
在 node_global 下創(chuàng)建 node_modules 文件夾
系統變量-新建
> 變量名:NODE_PATH
> 變量值:D:\Program Files\nodejs\node_global\node_modules
用戶變量
> C:\Users\beyondware\AppData\Roaming\npm
改成
> D:\Program Files\nodejs\node_global
### 安裝 cnpm
> npm install -g cnpm --registry=https://registry.npmmirror.com
查詢版本
> cnpm -v
### 修改 npm 源
查看當前 npm 源
> npm config get registry
修改 npm 源
> npm config set registry https://registry.npmmirror.com/
還原 npm 源
> npm config set registry https://registry.npmjs.org/
臨時修改
> npm install 包名 --registry=https://registry.npmmirror.com
查看配置列表
> npm config list
### nrm
npm
> https://github.com/Pana/nrm
安裝 nrm
> npm install -g nrm
列出 nrm 源
> nrm ls
使用 taobao
> nrm use taobao
測試響應速度
> nrm test taobao
添加鏡像地址
> nrm add URL 'registry_name'
刪除鏡像地址
> nrm del 'registry_name'
### npm 常用命令
初始化
> npm init
> npm init -y //全部 yes
安裝
> npm install
> npm i
> npm install -dev //開發(fā)環(huán)境
> npm install -g //全局安裝
安裝指定版本
> npm install 包名@版本號
> npm install 包名@latest
刪除
> npm uninstall
升級
> npm update
清空緩存
> npm cache clean --force
## yarn
> ~/.yarnrc
### 修改 yarn 源
查看當前 yarn 源
> yarn config get registry
修改 yarn 源
> yarn config set registry https://registry.npmmirror.com/
還原 yarn 源
> yarn config set registry https://registry.yarnpkg.com/
臨時修改
> yarn save 包名 --registry https://registry.npmmirror.com/
### 修改 yarn 環(huán)境變量
查看 yarn 版本
> yarn -v
創(chuàng)建 yarn_global 文件夾(全局安裝)
> yarn config set global-folder "D:\Program Files\Yarn\yarn_global"
創(chuàng)建 yarn_cache 文件夾(全局緩存)
> yarn config set cache-folder "D:\Program Files\Yarn\yarn_cache"
> yarn config set prefix "D:\Program Files\Yarn\yarn_global"
查看所有配置
> yarn config list
查看當前 bin 位置
> yarn global bin
添加到系統環(huán)境變量
> D:\Program Files\Yarn\yarn_global\bin
查看當前全局安裝位置
> yarn global dir
### yrm
> https://github.com/i5ting/yrm
安裝 yrm
> npm install -g yrm
列出 yrm 源
> yrm ls
使用 taobao
> yrm use taobao
測試訪問速度
> yrm test taobao
### cgr
cgr:npm、yarn
> https://github.com/daysai/cgr
> https://www.npmjs.com/package/cgr
### yarn 常用命令
初始化
> yarn init
安裝所有包
> yarn install
添加依賴項
> yarn add
> yarn add --dev //開發(fā)環(huán)境
> yarn global add //全局安裝
刪除
> yarn remove
升級
> yarn upgrade
> yarn up
列出已安裝
> yarn list
緩存列表
> yarn cache list
清空緩存
> yarn cache clean