> ## Documentation Index
> Fetch the complete documentation index at: https://better-router.bansal.io/llms.txt
> Use this file to discover all available pages before exploring further.

# shadcn/ui

> Add Tailwind CSS and shadcn/ui to a better-router Vite app.

This follows the [shadcn/ui Vite guide](https://ui.shadcn.com/docs/installation/vite), adapted for better-router: pages live in `src/routes`, and `betterRouter()` already registers `@/` and `@vitejs/plugin-react`.

## 1. Install better-router

Use the [Quickstart](https://better-router.bansal.io/quickstart.md) through step 2 (plugin enabled, default Vite entry files removed). You will add [`_document.tsx`](https://better-router.bansal.io/document) in step 2 below for global CSS.

## 2. Tailwind CSS v4

```bash theme={null}
npm install tailwindcss @tailwindcss/vite
```

Create global styles (for example `src/styles/globals.css`):

```css title="src/styles/globals.css" theme={null}
@import "tailwindcss";
```

Import that file from `src/routes/_document.tsx` (see [Document (\_document)](https://better-router.bansal.io/document.md) — side-effect import; the plugin mirrors it on the client entry):

```tsx title="src/routes/_document.tsx" theme={null}
import type { ReactNode } from "react";
import "../styles/globals.css";

export default function Document({
  children,
  stateScript,
  clientSrc,
  devScripts,
}: {
  children: ReactNode;
  stateScript: string;
  clientSrc: string;
  devScripts?: ReactNode;
}) {
  return (
    <html lang="en">
      <head>
        <meta charSet="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        {devScripts}
      </head>
      <body>
        <div id="app">{children}</div>
        <script dangerouslySetInnerHTML={{ __html: stateScript }} />
        <script type="module" src={clientSrc} />
      </body>
    </html>
  );
}
```

## 3. TypeScript paths

Add the `@/*` alias to `tsconfig.json` (same as the shadcn docs). If you kept Vite's split config instead of the [Quickstart](https://better-router.bansal.io/quickstart.md) `tsconfig.json`, add the same `paths` block to `tsconfig.app.json`:

```json title="tsconfig.json" theme={null}
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
```

`betterRouter()` also sets `@` → `src` in Vite. You still want the tsconfig paths so the editor and shadcn CLI agree.

## 4. Vite config

Do **not** add `@vitejs/plugin-react` again. Add Tailwind next to `betterRouter()`:

```ts title="vite.config.ts" theme={null}
import tailwindcss from "@tailwindcss/vite";
import { defineConfig } from "vite";
import { betterRouter } from "better-router/plugin";

export default defineConfig({
  plugins: [betterRouter(), tailwindcss()],
});
```

If the shadcn CLI asks for a manual `@` alias in `vite.config.ts`, you can skip it — the plugin already resolves `@/` to `src/`.

## 5. Initialize shadcn/ui

From the project root:

```bash theme={null}
npx shadcn@latest init
```

Accept the defaults or pick your style. The CLI writes `components.json`, updates `src/styles/globals.css` with theme tokens, and adds utilities under `src/lib` (and often a starter component under `src/components/ui`).

## 6. Add a component and use it on a route

```bash theme={null}
npx shadcn@latest add button
```

```tsx title="src/routes/index.tsx" theme={null}
import { Button } from "@/components/ui/button";

export default function Home() {
  return (
    <main className="flex min-h-svh flex-col items-center justify-center gap-4">
      <h1 className="text-2xl font-semibold">Home</h1>
      <Button>Click me</Button>
    </main>
  );
}
```

## 7. Run and preview

```bash theme={null}
npm run dev
```

Open `http://localhost:5173` and confirm the button renders with shadcn styles.

`npm run build` still emits `dist/client` and `dist/server`. For a static asset check only, `vite preview` serves **client** assets — it is not the full SSR app. Use `npm run dev` or your production server (see [Deployment](https://better-router.bansal.io/deployment.md)) to verify SSR + hydration.

## Client env with shadcn

Only variables prefixed with `PUBLIC_` are exposed to the browser via `import.meta.env`. See [Environment and secrets](https://better-router.bansal.io/environment.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.