yarn記錄
使用yarn代替npm
1.我們在安裝完node
之后就有了npm
,但是我們嫌棄比較慢,於是就使用了淘寶NPM鏡像cnpm
安裝cnpm
命令:
npm install -g cnpm --registry=https://registry.npm.taobao.org
2.我們嫌棄cnpm路徑問題以及丟包問題,更改npm倉庫。具體命令:
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
3.Nodejs中國鏡像,為中國內地的Node.js開發者准備的鏡像配置,大大提高node模塊安裝速度。
# 從registry地址安裝mirror-config-china
npm i -g mirror-config-china --registry=https://registry.npm.taobao.org
# 檢查是否安裝成功 如果安裝成功之后會出現 userconfig C:\Users\{YOUNAME}\.npmrc 這個里面寫了很多鏡像地址
npm config list
4.然后我們可以為項目生成鏡像配置
cd ~/my-project
mirror-config-china --registry=https://registry.npm.taobao.org
5.重點來了,我們使用yarn
# 全局安裝yarn
npm install -g yarn
# 同樣,我們也為yarn設置鏡像源
yarn config set registry https://registry.npm.taobao.org --global
yarn config set disturl https://npm.taobao.org/dist --global
# 安裝完 yarn 之后就可以用 yarn 代替 npm 了,例如用 yarn 代替 npm install 命令,用 yarn add 某第三方庫名代替 npm install 某第三方庫名。
# 為了更好用,順便我們再多配置點東西
phantomjs_cdnurl=https://bitbucket.org/ariya/phantomjs/downloads
sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
phantomjs_cdnurl "http://cnpmjs.org/downloads"
electron_mirror "https://npm.taobao.org/mirrors/electron/"
sqlite3_binary_host_mirror "https://foxgis.oss-cn-shanghai.aliyuncs.com/"
profiler_binary_host_mirror "https://npm.taobao.org/mirrors/node-inspector/"
chromedriver_cdnurl "https://cdn.npm.taobao.org/dist/chromedriver"
yarn命令與npm命令比較
說明 | npm命令 | Yarn命令 | yarn命令簡寫 |
---|---|---|---|
安裝某個依賴 | npm install XX --save | yarn add XX | |
安裝某個開發依賴 | npm install XX --dev | yarn add --dev XXX | yarn add -DE XXX |
初始化某個項目 | npm init | yarn init | |
移除某個依賴項目 | npm uninstall taco —save | yarn remove taco | |
更新某個依賴項目 | npm update taco —save | yarn upgrade taco | |
安裝某個全局依賴項目 | npm install taco --global | yarn global add taco | yarn add taco -g |
發布/登錄/登出,一系列NPM Registry操作 | npm publish/login/logout | yarn publish/login/logout | |
運行某個命令 | npm run/test | yarn run/test | |
查看本機全局安裝的依賴 | npm list -g --depth 0 | yarn global list | |
.. |
添加一個依賴包
yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]
例如
npm install react-router-dom @types/react-router-dom --save
yarn add react-router-dom @types/react-router-dom
yarn安裝的全局依賴沒有找到
例如
yarn global add umi
umi -v
'umi' 不是內部或外部命令,也不是可運行的程序 或批處理文件
yarn global bin
將獲得的地址添加到系統環境變量中。
默認地址 c:user\XXX\AppData\Local\Yarn\bin
https://blog.csdn.net/weixin_42214548/article/details/104122763