mirror of
https://github.com/shadcn-ui/ui.git
synced 2026-07-08 14:35:09 +00:00
* feat(v4): update home page * fix * fix: cards * feat(v4): charts page * feat: update pages * feat: colors * fix * feat: add docs * feat: mdx work * fix * fix * fix: sidebar * fix: lint * feat: updates * feat: update components * feat: fix docs * fix: responsive * feat: implement cmdk * fix: update navigation menu demo * fix: code style * fix: themes * feat: implement blocks page * fix: docs config * refactor * fix: outputFileTracingIncludes * fix * fix: output * fix * fix: registry * refactor: move docs * debug: docs * debug * revert * fix: mjs * deps: pin fumadocs * debug * fix: downgrade next * fix: index page * refactor: move mdx components * fix: remove copy button * fix * was it zod * yes it was * remove copy page * fix: color page * fix: colors page * fix: meta colors * fix: copy button * feat: sync registry * fix: registry build script * feat: update port * feat: clean up examples * fix * fix: mobile nav * fix: blur for mobile * fix: sidebar nav * feat: update examples * fix: build scripts * feat: update components * feat: restyle * fix: types * fix: styles * fix: margins * fix: screenshots * fix * feat: update theme * fix: charts nav * fix: image * feat: optimize images * fix: menu * fix: card * fix: border * check * feat: implement charts page * fix: charts * fix: og images * feat: extend touch * fix: static * fix: sizing * fix: mobile screenshots * fix: page nav * fix * feat: update favicon * fix: theme selector * fix: feedback * fix: sink * docs: update * fix: styles * chore: update registry * fix: command * fix * fix: minor updates * fix: typography on smaller devices * fix: format * fix: remove unused icon * feat: update favicon * fix: typography * docs: typography page * fix: steps
167 lines
4.6 KiB
Plaintext
167 lines
4.6 KiB
Plaintext
---
|
||
title: Monorepo
|
||
description: Using shadcn/ui components and CLI in a monorepo.
|
||
---
|
||
|
||
Until now, using shadcn/ui in a monorepo was a bit of a pain. You could add
|
||
components using the CLI, but you had to manage where the components
|
||
were installed and manually fix import paths.
|
||
|
||
With the new monorepo support in the CLI, we've made it a lot easier to use
|
||
shadcn/ui in a monorepo.
|
||
|
||
The CLI now understands the monorepo structure and will install the components,
|
||
dependencies and registry dependencies to the correct paths and handle imports
|
||
for you.
|
||
|
||
## Getting started
|
||
|
||
<Steps>
|
||
|
||
### Create a new monorepo project
|
||
|
||
To create a new monorepo project, run the `init` command. You will be prompted
|
||
to select the type of project you are creating.
|
||
|
||
```bash
|
||
npx shadcn@canary init
|
||
```
|
||
|
||
Select the `Next.js (Monorepo)` option.
|
||
|
||
```bash
|
||
? Would you like to start a new project?
|
||
Next.js
|
||
❯ Next.js (Monorepo)
|
||
```
|
||
|
||
This will create a new monorepo project with two workspaces: `web` and `ui`,
|
||
and [Turborepo](https://turbo.build/repo/docs) as the build system.
|
||
|
||
Everything is set up for you, so you can start adding components to your project.
|
||
|
||
Note: The monorepo uses React 19 and Tailwind CSS v4.
|
||
|
||
### Add components to your project
|
||
|
||
To add components to your project, run the `add` command **in the path of your app**.
|
||
|
||
```bash
|
||
cd apps/web
|
||
```
|
||
|
||
```bash
|
||
npx shadcn@canary add [COMPONENT]
|
||
```
|
||
|
||
The CLI will figure out what type of component you are adding and install the
|
||
correct files to the correct path.
|
||
|
||
For example, if you run `npx shadcn@canary add button`, the CLI will install the button component under `packages/ui` and update the import path for components in `apps/web`.
|
||
|
||
If you run `npx shadcn@canary add login-01`, the CLI will install the `button`, `label`, `input` and `card` components under `packages/ui` and the `login-form` component under `apps/web/components`.
|
||
|
||
### Importing components
|
||
|
||
You can import components from the `@workspace/ui` package as follows:
|
||
|
||
```tsx
|
||
import { Button } from "@workspace/ui/components/button"
|
||
```
|
||
|
||
You can also import hooks and utilities from the `@workspace/ui` package.
|
||
|
||
```tsx
|
||
import { useTheme } from "@workspace/ui/hooks/use-theme"
|
||
import { cn } from "@workspace/ui/lib/utils"
|
||
```
|
||
|
||
</Steps>
|
||
|
||
## File Structure
|
||
|
||
When you create a new monorepo project, the CLI will create the following file structure:
|
||
|
||
```txt
|
||
apps
|
||
└── web # Your app goes here.
|
||
├── app
|
||
│ └── page.tsx
|
||
├── components
|
||
│ └── login-form.tsx
|
||
├── components.json
|
||
└── package.json
|
||
packages
|
||
└── ui # Your components and dependencies are installed here.
|
||
├── src
|
||
│ ├── components
|
||
│ │ └── button.tsx
|
||
│ ├── hooks
|
||
│ ├── lib
|
||
│ │ └── utils.ts
|
||
│ └── styles
|
||
│ └── globals.css
|
||
├── components.json
|
||
└── package.json
|
||
package.json
|
||
turbo.json
|
||
```
|
||
|
||
## Requirements
|
||
|
||
1. Every workspace must have a `components.json` file. A `package.json` file tells npm how to install the dependencies. A `components.json` file tells the CLI how and where to install components.
|
||
|
||
2. The `components.json` file must properly define aliases for the workspace. This tells the CLI how to import components, hooks, utilities, etc.
|
||
|
||
```json showLineNumbers title="apps/web/components.json"
|
||
{
|
||
"$schema": "https://ui.shadcn.com/schema.json",
|
||
"style": "new-york",
|
||
"rsc": true,
|
||
"tsx": true,
|
||
"tailwind": {
|
||
"config": "",
|
||
"css": "../../packages/ui/src/styles/globals.css",
|
||
"baseColor": "zinc",
|
||
"cssVariables": true
|
||
},
|
||
"iconLibrary": "lucide",
|
||
"aliases": {
|
||
"components": "@/components",
|
||
"hooks": "@/hooks",
|
||
"lib": "@/lib",
|
||
"utils": "@workspace/ui/lib/utils",
|
||
"ui": "@workspace/ui/components"
|
||
}
|
||
}
|
||
```
|
||
|
||
```json showLineNumbers title="packages/ui/components.json"
|
||
{
|
||
"$schema": "https://ui.shadcn.com/schema.json",
|
||
"style": "new-york",
|
||
"rsc": true,
|
||
"tsx": true,
|
||
"tailwind": {
|
||
"config": "",
|
||
"css": "src/styles/globals.css",
|
||
"baseColor": "zinc",
|
||
"cssVariables": true
|
||
},
|
||
"iconLibrary": "lucide",
|
||
"aliases": {
|
||
"components": "@workspace/ui/components",
|
||
"utils": "@workspace/ui/lib/utils",
|
||
"hooks": "@workspace/ui/hooks",
|
||
"lib": "@workspace/ui/lib",
|
||
"ui": "@workspace/ui/components"
|
||
}
|
||
}
|
||
```
|
||
|
||
3. Ensure you have the same `style`, `iconLibrary` and `baseColor` in both `components.json` files.
|
||
|
||
4. **For Tailwind CSS v4, leave the `tailwind` config empty in the `components.json` file.**
|
||
|
||
By following these requirements, the CLI will be able to install ui components, blocks, libs and hooks to the correct paths and handle imports for you.
|