帶有許多 npm 腳本的 Monorepo (Monorepo with Many npm-scripts)


問題描述

帶有許多 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 CazettoLuke Storry)

參考文件

  1. Monorepo with Many npm‑scripts (CC BY‑SA 2.5/3.0/4.0)

#yarn-workspaces #lerna #monorepo #reactjs






相關問題

如何使用帶有打字稿和輸出文件夾的紗線工作區? (How to use yarn workspaces with typescript and out folders?)

如何在 Monorepo 中運行多個開發包 (How to run multiple packages in development inside a Monorepo)

帶有許多 npm 腳本的 Monorepo (Monorepo with Many npm-scripts)

使用紗線工作區導出枚舉時出現意外的令牌錯誤 (Unexpected token error exporting enums using yarn workspaces)

如何在 Expo 應用示例嵌套文件夾中熱重載開發包? (How to hot reload a development package in an Expo app example nested folder?)

將 monorepo 包放在包文件夾下是一種約定,還是 yarn 工作區期望這樣? (Is putting monorepo packages under a package folder a convention, or do yarn workspace expect that?)

通過創建具有循環依賴關係的 monorepo 導致錯誤 (Causing an error by creating a monorepo with circular dependencies)

Monorepo – Yarn 工作區 Typescript Node.JS 項目 – 運行 nodemon 時找不到模塊 (Monorepo – Yarn workspaces Typescript Node.JS project – cannot find module when running nodemon)

紗線工作區為每個運行 shell 命令 (Yarn workspaces run shell command for each)

紗線工作區共享包未在 create-react-app 中加載 (yarn workspaces shared package does not load in create-react-app)

如何使用 Yarn 工作區將共享依賴項添加到 monorepo? (How do I add shared dependencies to a monorepo using Yarn workspaces?)

使用紗線工作區在monorepo中跨項目共享配置變量? (Sharing config variables across projects in a monorepo using yarn workspaces?)







留言討論