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
- Biome for code linting and formatting
- Changesets for managing versioning and changelogs
pnpm build
- Build all packages, including the Storybook sitepnpm dev
- Run all packages locally and preview with Storybookpnpm test
- Test all packagespnpm lint
- Lint all packagespnpm changeset
- Generate a changesetpnpm clean
- Clean up allnode_modules
anddist
folders (runs each package's clean script)
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.
This Turborepo includes the following packages and applications:
apps/docs
: Component documentation site with Storybookpackages/ui
: Core React componentspackages/utils
: Shared React utilitiespackages/typescript-config
: Sharedtsconfig.json
s used throughout the Turborepopackages/biome-config
: biome config
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.
To make the core 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.
Run pnpm build
to confirm compilation is working correctly. You should see a folder /dist
which contains the compiled output.
└── dist
├── index.d.ts <-- Types
├── index.js <-- CommonJS version
└── index.mjs <-- ES Modules version
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
packages
folder - Support using module path aliases like
@ui-modules
for imports - Write MDX for component documentation pages
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.
To generate your changelog, run pnpm changeset
locally:
- 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 thechangeset
. - Which packages should have a major bump? – Press
space
to select the packages you want to bump versions for. - If doing the first major version, confirm you want to release.
- Write a summary for the changes.
- Confirm the changeset looks as expected.
- A new Markdown file will be created in the
changeset
folder with the summary and a list of the packages included.
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 ui-modules
as the npm organization. To change this, do the following:
- Rename folders in
packages/*
to replaceui-modules
with your desired scope - Search and replace
ui-modules
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"
- },