![Go-brown-side.sh]()
之前寫過一篇『
減少 node_modules 大小來加速部署 Node.js 專案』文章,透過
Yarn 指令可以移除不必要的模組,剩下的模組佔據整個專案大部分容量,那該如何針對留下的模組來瘦身呢?這週看到
Node.js 大神
TJ 又發了一個
Go 語言專案叫做
node-prune,此專案用來移除在
node_modules
內不必要的檔案,那哪些才是不必要的檔案呢?
預設刪除列表
底下是 node-prune 預設刪除的
檔案列表
var DefaultFiles = []string{
"Makefile",
"Gulpfile.js",
"Gruntfile.js",
".DS_Store",
".tern-project",
".gitattributes",
".editorconfig",
".eslintrc",
".jshintrc",
".flowconfig",
".documentup.json",
".yarn-metadata.json",
".travis.yml",
"LICENSE.txt",
"LICENSE",
"AUTHORS",
"CONTRIBUTORS",
".yarn-integrity",
}
預設
刪除目錄
var DefaultDirectories = []string{
"__tests__",
"test",
"tests",
"powered-test",
"docs",
"doc",
".idea",
".vscode",
"website",
"images",
"assets",
"example",
"examples",
"coverage",
".nyc_output",
}
預設刪除的
副檔名
var DefaultExtensions = []string{
".md",
".ts",
".jst",
".coffee",
".tgz",
".swp",
}
作者也非常好心,開了
WithDir
,
WithExtensions
… 等接口讓開發者可以動態調整名單。其實這專案不只可以用在 Node.js 專案,也可以用在 PHP 或者是 Go 專案上。
產生執行檔
對於非 Go 的開發者來說,要使用此套件還需要額外安裝 Go 語言環境才可以正常編譯出 Binary 檔案,也看到有人提問
無法搞定 Go 語言環境,所以我直接
Fork 此專案,再搭配
Drone CI 方式輕易產生各種環境的 Binary 檔案,現在只有產生 Windows, Linux 及 MacOS。大家可以從底下連結直接下載來試試看。下載完成,放到
/usr/local/bin
底下即可。使用方式很簡單,到專案底下直接執行
node-prune
$ node-prune
files total 16,674
files removed 4,452
size removed 18 MB
duration 1.547s