본문으로 건너뛰기
언어22
메뉴

문서 / 프레임워크

Vite

Vite + React 앱에 UI Loft 아이템을 추가하세요. Vite에는 먼저 Tailwind와 @ import 별칭이 필요해요. 그다음엔 아이템마다 명령어 하나면 돼요.

버전
React
필요
Tailwind 4 + shadcn + @ 별칭
설정 시간
약 5분

설정

  1. 앱 만들기

    이미 React + TypeScript 앱이 있다면 건너뛰세요.

    터미널
    npm create vite@latest my-app -- --template react-ts
    cd my-app
    npm install
  2. Tailwind 추가

    Tailwind의 Vite 플러그인과, 아래 설정에 쓸 Node 타입을 설치해요.

    터미널
    npm install tailwindcss @tailwindcss/vite
    npm install -D @types/node
  3. Tailwind 불러오기

    src/index.css의 내용을 모두 이 한 줄로 바꾸세요.

    src/index.css
    @import "tailwindcss";
  4. TypeScript에 @ 별칭 추가

    tsconfig.json과 tsconfig.app.json 둘 다 compilerOptions 아래에 paths를 추가하세요. baseUrl은 필요 없어요.

    tsconfig.json, tsconfig.app.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  5. Vite에 Tailwind와 별칭 추가

    vite.config.ts를 이 내용으로 바꾸세요.

    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. shadcn 설정

    components.json이 만들어지고 src/index.css에 테마가 채워져요. -d는 기본값을 써요.

    터미널
    npx shadcn@latest init -d
  7. 아이템 추가

    아이템 페이지에서 명령어를 복사하세요. 파일은 src/components/에 들어가요.

    터미널
    npx shadcn@latest add https://uiloft.dev/r/glow-button.json
  8. 사용하기

    앱 어디서나 import하세요.

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

알아 두면 좋아요

  • 여기에는 서버 렌더링이 없어서 shadcn이 "use client"를 빼요. 모든 아이템이 브라우저에서 그대로 실행돼요.
  • 이미 Tailwind 4와 @ 별칭이 있나요? shadcn 설정부터 시작하세요.
  • 아이템을 업데이트하려면 명령어를 다시 실행하세요. 파일을 덮어쓰기 전에 shadcn이 먼저 물어봐요.

다른 프레임워크