Skip to content

Add Workspace

Workspaces are folders that contain packages or applications. In a monorepo, workspaces are used to group related packages and applications together. In this guide, you will learn how to add new workspaces to your monorepo.

Command

This command allows you to add new workspaces to the monorepo.

bash
monopkg workspace add [workspaces...] [options]
bash
bun x monopkg workspace add [workspaces...] [options]
bash
npx monopkg workspace add [workspaces...] [options]
bash
yarn dlx monopkg workspace add [workspaces...] [options]

FYI

In the interactive mode, you can enter multiple workspace name to be added. The prompt will keep asking for the workspace name until you press Enter without entering a name.

Options

  • --cold - Cold run, skip creating the workspace folder.

Examples

Single Workspace

Add a new workspace named tools:

bash
monopkg workspace add tools
bash
bun x monopkg workspace add tools
bash
npx monopkg workspace add tools
bash
yarn dlx monopkg workspace add tools

Output

Folder Structure

json
├─ packages
|  ├─ pkg-a
|  ├─ pkg-b
├─ tools 
|  └─ .gitkeep 
└─ package.json

package.json

json
{
  "workspaces": [
    "packages/*",
    "tools/*"
  ]
}

Multiple Workspaces

Add multiple workspaces named tools and apps:

bash
monopkg workspace add tools apps
bash
bun x monopkg workspace add tools apps
bash
npx monopkg workspace add tools apps
bash
yarn dlx monopkg workspace add tools apps

Output

Folder Structure

json
├─ apps 
|  └─ .gitkeep 
├─ packages
|  ├─ pkg-a
|  ├─ pkg-b
├─ tools 
|  └─ .gitkeep 
└─ package.json

package.json

json
{
  "workspaces": [
    "apps/*", 
    "packages/*",
    "tools/*"
  ]
}

Skip Creating Workspace Folder

Add a new workspace named tools and skip creating the workspace folder:

bash
monopkg workspace add tools --cold
bash
bun x monopkg workspace add tools --cold
bash
npx monopkg workspace add tools --cold
bash
yarn dlx monopkg workspace add tools --cold

Output

Folder Structure

json
├─ packages
|  ├─ pkg-a
|  ├─ pkg-b
└─ package.json

package.json

json
{
  "workspaces": [
    "packages/*",
    "tools/*"
  ]
}

Released under the MIT License.