Skip to content
Language22
Menu

Docs / Frameworks

Vite

Add UI Loft items to a Vite + React app. Vite needs Tailwind and the @ import alias first; then every item is one command.

Version
React
Needs
Tailwind 4 + shadcn + @ alias
Setup time
About 5 minutes

Set up

  1. Create the app

    Skip this if you already have a React + TypeScript app.

    Terminal
    npm create vite@latest my-app -- --template react-ts
    cd my-app
    npm install
  2. Add Tailwind

    Tailwind's Vite plugin, and Node's types for the config below.

    Terminal
    npm install tailwindcss @tailwindcss/vite
    npm install -D @types/node
  3. Load Tailwind

    Replace everything in src/index.css with this line.

    src/index.css
    @import "tailwindcss";
  4. Add the @ alias for TypeScript

    Add paths under compilerOptions in both tsconfig.json and tsconfig.app.json. No baseUrl needed.

    tsconfig.json and tsconfig.app.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  5. Add Tailwind and the alias to Vite

    Replace vite.config.ts with this.

    vite.config.ts
    import path from "path"
    import tailwindcss from "@tailwindcss/vite"
    import react from "@vitejs/plugin-react"
    import { defineConfig } from "vite"
    
    export default defineConfig({
      plugins: [react(), tailwindcss()],
      resolve: {
        alias: {
          "@": path.resolve(__dirname, "./src"),
        },
      },
    })
  6. Set up shadcn

    It makes a components.json and fills src/index.css with the theme. -d takes the defaults.

    Terminal
    npx shadcn@latest init -d
  7. Add an item

    Copy the command from any item page. The file lands in src/components/.

    Terminal
    npx shadcn@latest add https://uiloft.dev/r/glow-button.json
  8. Use it

    Import it anywhere in your app.

    src/App.tsx
    import { GlowButton } from "@/components/glow-button"
    
    export default function App() {
      return <GlowButton>Get started</GlowButton>
    }

Good to know

  • There's no server rendering here, so shadcn leaves out "use client". Every item runs in the browser as is.
  • Already have Tailwind 4 and the @ alias? Start at Set up shadcn.
  • To update an item, run its command again. shadcn asks before it overwrites a file.

Other frameworks