Skip to content

一个用 pnpm + turbo 搭建的 monorepo 的模版仓库。A monorepo template with pnpm and turbo

Notifications You must be signed in to change notification settings

ivonzhang/quick-mono

Repository files navigation

Description

English | 中文

This repository is a monorepo that manages multiple projects in a single codebase using pnpm workspace. It also supports incremental builds with turbo.

Table of Contents

Purpose

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.

Project Structure

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.

Getting Started

  • 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 run pnpm 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

Prerequisites

  • Node.js
  • pnpm
  • turbo

Installation

  1. Clone the repository:

    git clone https://github.com/ivonzhang/monorepo-demo.git
    cd monorepo-demo
  2. Install dependencies:

    pnpm i

Running Projects

To run a specific project, navigate to the project's directory and run the start script:

cd apps/frontend/dashboard
pnpm run dev

Using Hot Reload

To enable hot reload for local development, follow these steps:

  1. Navigate to the package or app you want to develop. For example, to develop the ui package:

    cd packages/ui
  2. Run the development script:

    pnpm run dev
  3. 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.

Adding a New Project

  1. Create a new directory under packages/:

    mkdir packages/project-c
  2. Initialize a new project:

    cd packages/project-c
    pnpm init
  3. Add the necessary dependencies and scripts.

Common Scripts

  • Build all projects:

    pnpm build
  • Start the projects:

    pnpm run dev

Incremental Builds with Turbo

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.

License

This project is licensed under the MIT License.

About

一个用 pnpm + turbo 搭建的 monorepo 的模版仓库。A monorepo template with pnpm and turbo

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published