yarn npm link 命令解析

npm和yarn的區別

yarn客戶端包官網地址:https://yarnpkg.com/en/docs/install#windows-stable html

在win環境下使用yarn安裝 vue-cli

 

0.安裝  (沒裝npm的時候也能夠用客戶端安裝 :https://yarnpkg.com/en/docs/install#windows-stable )vue

npm install -g yarn

顯示全局包位置: yarn global dirnode

設置緩存文件夾 位置  yarn config set cache-folder c:\yarn\cachenginx

設置全局包位置:  1. you need to add the line --global-folder "C:\ds_raiser\common\yarn\data\global"manually into your .yarnrc file.git

                            2.    直接用這句命令不起做用  yarn config set global-folder "C:\ds_raiser\common\yarn\data\global    參考:https://github.com/yarnpkg/yarn/issues/5746github

 關於npm和yarn的全局包位置務必看下這個 ****** 記一次npm 和 yarn 安裝的折騰web

一、初始化一個新的項目vue-cli

yarn init

二、添加一個依賴包docker

yarn add [package] yarn add [package]@[version] yarn add [package]@[tag]

三、安裝全部的依賴包npm

yarn 或者 yarn install

 

改源:https://blog.csdn.net/p358278505/article/details/72916548 

yarn config set registry https://registry.npm.taobao.org

查看

yarn config get registry

 

四、npm 與 yarn命令比較

 

NPM YARN 說明
npm init yarn init 初始化某個項目
npm install/link yarn install/link 默認的安裝依賴操做
npm install taco —save yarn add taco 安裝某個依賴,而且默認保存到package.
npm uninstall taco —save yarn remove taco 移除某個依賴項目
npm install taco —save-dev yarn add taco —dev 安裝某個開發時依賴項目
npm update taco —save yarn upgrade taco 更新某個依賴項目
npm install taco --global yarn global add taco 安裝某個全局依賴項目
npm publish/login/logout yarn publish/login/logout 發佈/登陸/登出,一系列NPM Registry操做
npm run/test yarn run/test 運行某個命令
npm config ls yarn global dir 顯示yarn安裝路徑
     
 

CLI commands comparison

npm (v5) Yarn
npm install yarn install
(N/A) yarn install --flat
(N/A) yarn install --har
npm install --no-package-lock yarn install --no-lockfile
(N/A) yarn install --pure-lockfile
npm install [package] --save yarn add [package]
npm install [package] --save-dev yarn add [package] --dev
(N/A) yarn add [package] --peer
npm install [package] --save-optional yarn add [package] --optional
npm install [package] --save-exact yarn add [package] --exact
(N/A) yarn add [package] --tilde
npm install [package] --global yarn global add [package]
npm update --global                   yarn global upgrade                    
npm rebuild yarn add --force
npm uninstall [package] yarn remove [package]
npm cache clean yarn cache clean [package]
rm -rf node_modules && npm install   yarn upgrade                          
npm version major                     yarn version --major                  
npm version minor                     yarn version --minor                  
npm version patch                     yarn version --patch                  
 

 

npm link 命令解析

 文字轉的

對開發者而言,這算是最有價值的命令。假設咱們開發了一個模塊叫 test ,而後咱們在 test-example 裏引用這個模塊 ,每次 test 模塊的變更咱們都須要反映到 test-example 模塊裏。不要擔憂,有了 npm link 命令一切變的很是容易。

首先咱們須要把 test 連接到全局模式下:

cd ~/work/node/test # 進入test模塊目錄
npm link # 建立連接到$PREFIX/lib/node_modules

那麼 test 的模塊將被連接到 $PREFIX/lib/node_modules 下,就像個人機器上 $PREFIX 指到 /usr/local ,那麼 /usr/local/lib/node_modules/test 將會連接到 ~/work/node/test 下。執行腳本 bin/test.js 被連接到 /usr/local/bin/test 上。

接下來咱們須要把 test 引用到 test-example 項目中來:

cd ~/work/node/test-example # 進入test-example模塊目錄
npm link test # 把全局模式的模塊連接到本地

npm link test 命令會去 $PREFIX/lib/node_modules 目錄下查找名叫 test 的模塊,找到這個模塊後把 $PREFIX/lib/node_modules/test 的目錄連接到 ~/work/node/test-example/node_modules/test 這個目錄上來。

如今任何 test 模塊上的改動都會直接映射到 test-example 上來。

 

再好比假設咱們開發不少應用,每一個應用都用到 Coffee-script :

npm install coffee-script -g # 全局模式下安裝coffee-script
cd ~/work/node/test # 進入開發目錄
npm link coffee-script # 把全局模式的coffee-script模塊連接到本地的node_modules下
cd ../test-example # 進入另外的一個開發目錄
npm link coffee-script # 把全局模式的coffee-script模塊連接到本地
npm update coffee-script -g # 更新全局模式的coffee-script,全部link過去的項目同時更新了。

yarn 國內加速,修改鏡像源


yarn config set registry https://registry.npm.taobao.org

相關文章
相關標籤/搜索