CLI 介紹
Yarn 提供一套豐富的指令列指令來幫助你使用,這包含安裝、管理、發佈等。
雖然這裡列出了所有以字母排序的指令,但其中最常使用的指令為以下:
yarn add
: 在目前的專案中安裝套件。yarn init
: 初始化你的專案。yarn install
: 安裝所有在package.json
中列出的相依性。yarn publish
: 發佈你的套件到套件管理器上。yarn remove
: 移除已經沒有在使用的套件。
預設指令
直接執行 yarn
而不包含任何指令將等同執行 yarn install
,並傳遞參數給它。
用戶自定義腳本
執行yarn <script> [<args>]
將會執行使用者自定義腳本
。 參考yarn run
。
本地安裝的 CLI {#locally-installed-clis.toc}
執行yarn <command> [<args>]
將會執行當前包内安裝過的(本地端,而非全域)對應名稱的命令,這樣就可以不必為了一些簡單的場景而專門去配置自定義腳本。
Concurrency 與 --mutex
當在同一台伺服器上使用同一個使用者執行多個 yarn 時,你可以確保同時只有一個 yarn 在執行 (同時可以避免指令衝突),只需使用全域的參數 --mutex
加上 file
或 network
。
若使用 file
, Yarn 預設會讀寫一個互斥鎖定檔 .yarn-single-instance
在目前工作目錄下,同時也可以指定不同的路徑或檔名。
--mutex file
--mutex file:/tmp/.yarn-mutex
若使用 network
, Yarn 預設會在 port 31997
建立一個伺服器,你也可以指定使用另一個 port。
--mutex network
--mutex network:30330
Verbose output with --verbose
Running yarn <command> --verbose
will print verbose info for the execution (creating directories, copying files, HTTP requests, etc.).