<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Afzal Diwan</title>
    <description>The latest articles on DEV Community by Afzal Diwan (@afzalhusen).</description>
    <link>https://dev.to/afzalhusen</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1033487%2F56367a86-17a7-428b-b927-8c3da5bd5592.png</url>
      <title>DEV Community: Afzal Diwan</title>
      <link>https://dev.to/afzalhusen</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/afzalhusen"/>
    <language>en</language>
    <item>
      <title>Create Turborepo with NextJS, Tailwind v4 and Shadcn (React 19)</title>
      <dc:creator>Afzal Diwan</dc:creator>
      <pubDate>Fri, 28 Mar 2025 16:15:11 +0000</pubDate>
      <link>https://dev.to/afzalhusen/create-turborepo-with-nextjs-tailwind-v4-and-shadcn-react-19-o0b</link>
      <guid>https://dev.to/afzalhusen/create-turborepo-with-nextjs-tailwind-v4-and-shadcn-react-19-o0b</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;What is Turborepo ?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Turborepo, developed by Vercel, is a powerful build system tool for JavaScript and TypeScript codebases that makes managing monorepos easier by optimizing workflows, speeding up build times, and ensuring consistency across projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Key features of Turborepo&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Incremental Caching:&lt;/strong&gt; Avoids rebuilding unchanged code, significantly improving build times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Parallel Execution:&lt;/strong&gt; Runs tasks across multiple projects simultaneously.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remote Caching:&lt;/strong&gt; Speeds up CI/CD pipelines by reusing cached results across different environments&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Efficient Dependency Management:&lt;/strong&gt; Uses a single &lt;code&gt;package.json&lt;/code&gt; or workspace approach to manage dependencies.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setting Up a Turborepo Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Step  1. Initialize a New Monorepo&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-turbo@latest my-turborepo
cd my-turborepo
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This starter repository includes&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two deployable NextJS applications in &lt;code&gt;apps&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Three &lt;code&gt;packages&lt;/code&gt; libraries for use in the rest of the monorepo
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;my-turborepo/
├── apps/
│   ├── web/                # First Next.js application
│   │   ├── app/            # Core directory for App Router
│   │   │   ├── globals.css # Global styles
│   │   │   ├── layout.tsx  # Root layout component
│   │   │   └── page.tsx    # Home page component ("/")
│   │   ├── public/         # Static assets (images, fonts, etc.)
│   │   ├── next.config.js  # Next.js configuration file
│   │   ├── tsconfig.json   # TypeScript configuration
│   │   └── package.json    # Project dependencies and scripts
│   └── docs/               # Second Next.js application
│       ├── app/            # Core directory for App Router
│       │   ├── globals.css # Global styles
│       │   ├── layout.tsx  # Root layout component
│       │   └── page.tsx    # Home page component ("/")
│       ├── public/         # Static assets (images, fonts, etc.)
│       ├── next.config.js  # Next.js configuration file
│       ├── tsconfig.json   # TypeScript configuration
│       └── package.json    # Project dependencies and scripts
├── packages/               # Shared packages
│   ├── ui/                 # Shared UI components
│   │   ├── button.tsx      # Example shared button component
│   │   ├── input.tsx       # Example shared input component
│   │   └── package.json    # Package dependencies and scripts
│   └── eslint-config-custom/ # Shared ESLint configuration
│       ├── index.js        # ESLint configuration
│       └── package.json    # Package dependencies and scripts
├── turbo.json              # Turborepo configuration
├── package.json            # Root package dependencies and scripts
└── pnpm-workspace.yaml     # pnpm workspaces configuration

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2. Installing &lt;code&gt;turbo&lt;/code&gt; globally&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm install turbo --global
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3. Installing and setting up Tailwindcss V4 in UI package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd packages/ui
pnpm install tailwindcss @tailwindcss/postcss postcss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once Tailwindcss and postcss plugin is installed, create a &lt;code&gt;postcss.config.mjs&lt;/code&gt; file and add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const config = {
  plugins: ["@tailwindcss/postcss"],
};

export default config;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;default.css&lt;/code&gt; inside &lt;code&gt;src/styles&lt;/code&gt;  folder of ui package and add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "tailwindcss";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an export alias for &lt;code&gt;default.css&lt;/code&gt;  and &lt;code&gt;postcss.config.mjs&lt;/code&gt; in &lt;code&gt;packages.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "@repo/ui",
  "version": "0.0.0",
  "private": true,
  "exports": {
    "./postcss.config": "./postcss.config.mjs",
    "./styles/*": "./src/styles/*"
  },
  "scripts": {
    "lint": "eslint . --max-warnings 0",
    "generate:component": "turbo gen react-component",
    "check-types": "tsc --noEmit"
  },
  "devDependencies": {
    "@repo/eslint-config": "workspace:*",
    "@repo/typescript-config": "workspace:*",
    "@tailwindcss/postcss": "^4.0.15",
    "@turbo/gen": "^2.4.4",
    "@types/node": "^22.13.10",
    "@types/react": "19.0.10",
    "@types/react-dom": "19.0.4",
    "eslint": "^9.22.0",
    "tailwindcss": "^4.0.15",
    "typescript": "5.8.2"
  },
  "dependencies": {
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 4. Using Tailwindcss V4 in Nextjs apps&lt;br&gt;
 Install Tailwindcss v4 and postcss in your NextJs apps&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm install tailwindcss @tailwindcss/postcss postcss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then  create a &lt;code&gt;postcss.config.mjs&lt;/code&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//using the config exported from packages/ui
export { default } from "@repo/ui/postcss.config"; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find &lt;code&gt;globals.css&lt;/code&gt; in your Nextjs app and add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import "tailwindcss";
@import "@repo/ui/styles/default.css";

@source '../../../packages/ui';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don’t forget to add &lt;code&gt;@repo/ui&lt;/code&gt;  as dependency in &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  "dependencies": {
    "@repo/ui": "workspace:*",
  },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: Since i am using pnpm package manage i had to add &lt;code&gt;"@repo/ui": "workspace:*"&lt;/code&gt; , if you are using yarn or npm add the package dependency  &lt;code&gt;"@repo/ui": "*"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Verify if its working&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr19jwphs516prw0pv241.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr19jwphs516prw0pv241.png" alt="Image description" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 5. Adding Shadcn ui&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd packages/ui
pnpm add class-variance-authority clsx tailwind-merge lucide-react tw-animate-css

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;components.json&lt;/code&gt; file in &lt;code&gt;packages/ui&lt;/code&gt; add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "$schema": "https://ui.shadcn.com/schema.json",
  "style": "new-york",
  "rsc": true,
  "tsx": true,
  "tailwind": {
    "config": "",
    "css": "src/styles/default.css",
    "baseColor": "zinc",
    "cssVariables": true
  },
  "iconLibrary": "lucide",
  "aliases": {
    "components": "@repo/ui/components",
    "ui": "@repo/ui/components/shadcn"
    "utils": "@repo/ui/lib/utils",
    "lib": "@repo/ui/lib",
    "hooks": "@repo/ui/hooks"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Configure the path aliases in your &lt;code&gt;packages/ui/tsconfig.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "extends": "@repo/typescript-config/react-library.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@repo/ui/*": ["./src/*"],
    }
  },
  "include": ["src"],
  "exclude": ["node_modules"]
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create &lt;code&gt;lib/utils.ts&lt;/code&gt; file in &lt;code&gt;packages/ui/src&lt;/code&gt;  and add the following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can install Shadcn components using shadcn CLI, let try it out&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx shadcn@latest add button
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install the button component in &lt;code&gt;packages/ui/src/components/shadcn&lt;/code&gt;&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5mk1eh3htnh98pidba1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw5mk1eh3htnh98pidba1.png" alt="Image description" width="563" height="287"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To use the components you need add a path alias in &lt;code&gt;exports&lt;/code&gt;in &lt;code&gt;package.json&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "@repo/ui",
  "version": "0.0.0",
  "private": true,
  "exports": {
    "./*": "./src/*.tsx",
    "./lib/utils": "./src/lib/utils.ts",
    "./postcss.config": "./postcss.config.mjs",
    "./styles/*": "./src/styles/*",
  },
  "peerDependencies": {
    "react": "^19.0.0",
    "react-dom": "^19.0.0"
  },
  "scripts": {
    "lint": "eslint . --max-warnings 0",
    "generate:component": "turbo gen react-component",
    "check-types": "tsc --noEmit"
  },
  "devDependencies": {
    "@repo/eslint-config": "workspace:*",
    "@repo/typescript-config": "workspace:*",
    "@tailwindcss/postcss": "^4.0.15",
    "@turbo/gen": "^2.4.4",
    "@types/node": "^22.13.10",
    "@types/react": "19.0.10",
    "@types/react-dom": "19.0.4",
    "eslint": "^9.22.0",
    "tailwindcss": "^4.0.15",
    "typescript": "5.8.2"
  },
  "dependencies": {
    "@radix-ui/react-slot": "^1.1.2",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "lucide-react": "^0.483.0",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "tailwind-merge": "^3.0.2",
    "tw-animate-css": "^1.2.4"
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can use  the shadcn components in your nextjs applications&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//page.tsx

import { Button } from "@repo/ui/components/shadcn/button";

const Home = () =&amp;gt; {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Button&amp;gt;Hello world&amp;lt;/Button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Home;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Monorepos offer a powerful way to manage multiple projects under a single repository, but they can introduce challenges in scalability and performance. &lt;strong&gt;Turborepo&lt;/strong&gt; solves these issues by providing a high-performance build system that optimizes dependency management and execution.&lt;/p&gt;

&lt;p&gt;By following best practices and leveraging Turborepo’s caching and parallel execution, you can efficiently manage your monorepo projects.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
