問題描述
帶有許多 npm 腳本的 Monorepo (Monorepo with Many npm‑scripts)
在你的 Monorepos 中,隨著你獲得越來越多的包,根 package.json 獲得許多 npm 腳本是正常的嗎?我正在映射根目錄中的所有包腳本以使其更容易,這是一個好方法嗎?當我需要開發依賴包時這是正常的,比如安裝在組件庫中的 i18n lib 安裝在 CRM 中。我需要在 dev 上運行所有 3 個,這很正常,對嗎?
參考解法
方法 1:
First question to ask yourself is ‑ do you need all those scripts to be defined?
Often just the most common scripts can be defined in package.json
, and the rest mentioned in documentation.
If you want to have many scripts, and find yourself needing to run multiple ones, then npm‑run‑all is a very useful package to run multiple scripts in serial or parallel, and can group/search by wildcard.
For example:
"scripts": {
"test:frontend": "jest",
"test:e2e": "cypress run",
"test:scripts": "bash ./script.sh",
"test": "npm‑run‑all ‑‑parallel test:**",
"clean": "rimraf ./dist",
"lint ": "prettier",
"build:fe": "vue‑cli‑service build",
"build:be": "node build.js",
"prePublish": "npm‑run‑all ‑‑serial clean lint build:**"
}
(by Cazetto、Luke Storry)