VercelLogotypeVercelLogotype
LoginSign Up
Back to Templates

Design System with Turborepo

This is an official starter Turborepo with a single Storybook documentation site, a shared UI component library, and three local packages.

DeployView Demo
turborepo-design-system-starter

Turborepo Design System Starter

This is a community-maintained example. If you experience a problem, please submit a pull request with a fix. GitHub Issues will be closed.

This guide explains how to use a React design system starter powered by:

  • šŸŽ Turborepo — High-performance build system for Monorepos
  • šŸš€ React — JavaScript library for user interfaces
  • šŸ›  Tsup — TypeScript bundler powered by esbuild
  • šŸ“– Storybook — UI component environment powered by Vite

As well as a few others tools preconfigured:

  • TypeScript for static type checking
  • ESLint for code linting
  • Prettier for code formatting
  • Changesets for managing versioning and changelogs
  • GitHub Actions for fully automated package publishing

Using this example

Run the following command:

npx create-turbo@latest -e design-system

Useful Commands

  • pnpm build - Build all packages, including the Storybook site
  • pnpm dev - Run all packages locally and preview with Storybook
  • pnpm lint - Lint all packages
  • pnpm changeset - Generate a changeset
  • pnpm clean - Clean up all node_modules and dist folders (runs each package's clean script)

Turborepo

Turborepo is a high-performance build system for JavaScript and TypeScript codebases. It was designed after the workflows used by massive software engineering organizations to ship code at scale. Turborepo abstracts the complex configuration needed for monorepos and provides fast, incremental builds with zero-configuration remote caching.

Using Turborepo simplifies managing your design system monorepo, as you can have a single lint, build, test, and release process for all packages. Learn more about how monorepos improve your development workflow.

Apps & Packages

This Turborepo includes the following packages and applications:

  • apps/docs: Component documentation site with Storybook
  • packages/ui: Core React components
  • packages/typescript-config: Shared tsconfig.jsons used throughout the Turborepo
  • packages/eslint-config: ESLint preset

Each package and app is 100% TypeScript. Workspaces enables us to "hoist" dependencies that are shared between packages to the root package.json. This means smaller node_modules folders and a better local dev experience. To install a dependency for the entire monorepo, use the -w workspaces flag with pnpm add.

This example sets up your .gitignore to exclude all generated files, other folders like node_modules used to store your dependencies.

Compilation

To make the ui library code work across all browsers, we need to compile the raw TypeScript and React code to plain JavaScript. We can accomplish this with tsup, which uses esbuild to greatly improve performance.

Running pnpm build from the root of the Turborepo will run the build command defined in each package's package.json file. Turborepo runs each build in parallel and caches & hashes the output to speed up future builds.

For @acme/ui, the build command is equivalent to the following:

tsup src/*.tsx --format esm,cjs --dts --external react

tsup compiles all of the components in the design system individually, into both ES Modules and CommonJS formats as well as their TypeScript types. The package.json for @acme/ui then instructs the consumer to select the correct format:

{
"name": "@acme/ui",
"version": "0.0.0",
"sideEffects": false,
"exports":{
"./button": {
"types": "./src/button.tsx",
"import": "./dist/button.mjs",
"require": "./dist/button.js"
}
}
}

Run pnpm build to confirm compilation is working correctly. You should see a folder ui/dist which contains the compiled output.

ui
└── dist
ā”œā”€ā”€ button.d.ts <-- Types
ā”œā”€ā”€ button.js <-- CommonJS version
ā”œā”€ā”€ button.mjs <-- ES Modules version
└── button.d.mts <-- ES Modules version with Types

Components

Each file inside of ui/src is a component inside our design system. For example:

import * as React from 'react';
export interface ButtonProps {
children: React.ReactNode;
}
export function Button(props: ButtonProps) {
return <button>{props.children}</button>;
}
Button.displayName = 'Button';

When adding a new file, ensure that its specifier is defined in package.json file:

{
"name": "@acme/ui",
"version": "0.0.0",
"sideEffects": false,
"exports":{
"./button": {
"types": "./src/button.tsx",
"import": "./dist/button.mjs",
"require": "./dist/button.js"
}
// Add new component exports here
}
}

Storybook

Storybook provides us with an interactive UI playground for our components. This allows us to preview our components in the browser and instantly see changes when developing locally. This example preconfigures Storybook to:

  • Use Vite to bundle stories instantly (in milliseconds)
  • Automatically find any stories inside the stories/ folder
  • Support using module path aliases like @acme/ui for imports
  • Write MDX for component documentation pages

For example, here's the included Story for our Button component:

import { Button } from '@acme/ui/button';
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
<Meta title="Components/Button" component={Button} />
# Button
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget consectetur tempor, nisl nunc egestas nisi, euismod aliquam nisl nunc euismod.
## Props
<Props of={Box} />
## Examples
<Preview>
<Story name="Default">
<Button>Hello</Button>
</Story>
</Preview>

This example includes a few helpful Storybook scripts:

  • pnpm dev: Starts Storybook in dev mode with hot reloading at localhost:6006
  • pnpm build: Builds the Storybook UI and generates the static HTML files
  • pnpm preview-storybook: Starts a local server to view the generated Storybook UI

Versioning & Publishing Packages

This example uses Changesets to manage versions, create changelogs, and publish to npm. It's preconfigured so you can start publishing packages immediately.

You'll need to create an NPM_TOKEN and GITHUB_TOKEN and add it to your GitHub repository settings to enable access to npm. It's also worth installing the Changesets bot on your repository.

Generating the Changelog

To generate your changelog, run pnpm changeset locally:

  1. Which packages would you like to include? – This shows which packages and changed and which have remained the same. By default, no packages are included. Press space to select the packages you want to include in the changeset.
  2. Which packages should have a major bump? – Press space to select the packages you want to bump versions for.
  3. If doing the first major version, confirm you want to release.
  4. Write a summary for the changes.
  5. Confirm the changeset looks as expected.
  6. A new Markdown file will be created in the changeset folder with the summary and a list of the packages included.

Releasing

When you push your code to GitHub, the GitHub Action will run the release script defined in the root package.json:

turbo run build --filter=docs^... && changeset publish

Turborepo runs the build script for all publishable packages (excluding docs) and publishes the packages to npm. By default, this example includes acme as the npm organization. To change this, do the following:

  • Rename folders in packages/* to replace acme with your desired scope
  • Search and replace acme with your desired scope
  • Re-run pnpm install

To publish packages to a private npm organization scope, remove the following from each of the package.json's

- "publishConfig": {
- "access": "public"
- },
GitHub Repovercel/turbo
LicenseView License
Use Cases
DocumentationMonorepos
Stack
ReactCSS Modules

Related Templates

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • v0

        Build applications with AI

      • AI SDK

        The AI Toolkit for TypeScript

      • AI Gateway

        One endpoint, all your models

      • Vercel Agent

        An agent that knows your stack

      • Sandbox

        AI workflows in live environments

    • Core Platform
      • CI/CD

        Helping teams ship 6Ɨ faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
Back to Templates
DeployView Demo

Monorepo with Turborepo

Learn to implement a monorepo with a two Next.js sites that has installed three local packages.
Monorepo with Turborepo

Turborepo & Next.js Starter

This is an official starter Turborepo with two Next.js sites and three local packages
Turborepo & Next.js Starter

Turborepo & SvelteKit Starter

This is an official starter Turborepo with two SvelteKit apps and two local packages.
Turborepo & SvelteKit Starter
v0

Build applications with AI

AI SDK

The AI Toolkit for TypeScript

AI Gateway

One endpoint, all your models

Vercel Agent

An agent that knows your stack

Sandbox

AI workflows in live environments

CI/CD

Helping teams ship 6Ɨ faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea