Introduction
In this guide, we will explain how to use shadcn in Nx monorepo with Next.js.
1. Initialize Nx and Create a Next.js Project
2. Add Tailwind
3. Add Library for shadcn
After creating the library, perform the following steps:
- Delete
server.ts
. - Create a
components
folder at the root of thesrc
folder.
At this point, your directory structure should look like this:
4. Add shadcn/ui
Edit tailwind.config.js
:
Add global.css
:
5. Add util.ts for shadcn
utils.ts
6. Add component.json in the root directory
components.json
7. Add tsconfig.json in the root directory
The tsconfig.json
is necessary for shacn/ui CLI commands.
tsconfig.json
With these steps, your setup is complete.
8. Implement shadcn/ui Components
Use the shadcn/ui CLI to install components:
Edit the component's tsx file:
- Add
'use client'
. - Resolve the
@nx/enforce-module-boundaries
warning.
Add exports for the components in index.ts
:
Implement the component in page.tsx
: