This repository is a monorepo that manages multiple projects in a single codebase using pnpm workspace. It also supports incremental builds with turbo.
The purpose of this repository is to enable developers to quickly set up a monorepo for business development. Developers can use the current project structure to develop their own business logic and organize their own monorepo.
monorepo-demo/
├── apps/
│ ├── backend/
│ └── frontend/
│ ├── dashboard/
│ └── home/
├── packages/
│ ├── cli/
│ └── tools/
│ └── ui/
├── package.json
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
└── README.md
- apps/: Contains business logic code.
- backend/: Backend service code.
- frontend/: Frontend application code.
- dashboard/: Example application demonstrating the integration of the packages/ui library.
- home/: Another frontend application.
- packages/: Contains all the shared libraries.
- cli/: Scripts for managing the monorepo.
- tools/: Common utility functions for the project.
- ui/: UI component library.
- Install pnpm
- Install turbo globally:
npm install -g turbo
- At the root directory, run
pnpm i
to install all dependencies - Open the
apps/frontend/dashboard
directory, and runpnpm run dev
to start the example application. - If you want to use hot reload in the packages project, you can open the project you want to develop and run
pnpm run dev
- Node.js
- pnpm
- turbo
-
Clone the repository:
git clone https://github.com/ivonzhang/monorepo-demo.git cd monorepo-demo
-
Install dependencies:
pnpm i
To run a specific project, navigate to the project's directory and run the start script:
cd apps/frontend/dashboard
pnpm run dev
To enable hot reload for local development, follow these steps:
-
Navigate to the package or app you want to develop. For example, to develop the
ui
package:cd packages/ui
-
Run the development script:
pnpm run dev
-
In another terminal, navigate to the app that uses the package. For example, to run the
dashboard
app:cd apps/frontend/dashboard pnpm run dev
Changes made in the ui
package will now be reflected in the dashboard
app without needing to restart the app.
-
Create a new directory under
packages/
:mkdir packages/project-c
-
Initialize a new project:
cd packages/project-c pnpm init
-
Add the necessary dependencies and scripts.
-
Build all projects:
pnpm build
-
Start the projects:
pnpm run dev
To use turbo for incremental builds, you can run the following command:
turbo run build
This will build only the projects that have changed since the last build, speeding up the build process significantly.
This project is licensed under the MIT License.