yarn autoclean


yarn autoclean [-I/--init] [-F/--force]

Autoclean 指令透過從相依文件中移除不需要的檔案和資料夾來釋放空間 這會減少專案下的 node_modules 中的檔案數量,當你需要把整個套件放進版本控制系統時這很有用。

附註:這個指令是進階用法, 除非你遇到 node_modules 中檔案過多的問題,否則不建議你使用這個指令, 此命令將會永久刪除node_modules中的那些會造成套件停止運作的檔案

Autoclean 默認為disabled。 若要啟動,手動創建一個 .yarnclean 檔,或者執行 yarn autoclean --init 來建一個預設内容的檔案。 .yarnclean 擋應該被加入到版本控制。

當一個套件存在 .yarnclean 文件,autoclean 功能就會啟用。清除執行的時機為:

  • install 之後
  • add 之後
  • 如果 yarn autoclean --force 在執行

The clean is performed by reading each line of the .yarnclean file and using each as a glob pattern of files to delete.


-I/--init : 創建 .yarnclean 文件(如果還不存在)並增加默認內容。 這個檔案應該被檢查及編輯,以設置哪些檔案應該被清除。 如果檔案已經存在,它將不會被覆寫。

-F/--force : 如果 .yarnclean 文件存在,執行其清除流程。如果該文件不存在,不做任何事。


When the yarn autoclean --init command is used to create a .yarnclean file, it will be pre-populated with a set of default items for deletion. This default list is a guess at what is likely not needed. It is impossible to predict all directories and files that are actually unnecessary for all existing and future NPM packages, so this default list may cause a package to no longer work.

It is highly recommended that you manually review the default entries in .yarnclean and customize them to fit your needs.

If you discover the autoclean process is deleting files that are needed for a package to work properly, then you should remove the corresponding entry from the .yarnclean file.


You decide all YAML and Markdown files in all your dependencies installed in node_modules can be safely deleted. You make a .yarnclean file containing:


You then run yarn install or yarn autoclean --force. The clean process will delete all *.yaml and *.md files within node_modules/ recursively (including nested transitive dependencies).