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

문서 / 프레임워크

Astro

Astro 사이트에 UI Loft 아이템을 추가하세요. Astro에는 먼저 React와 Tailwind를 추가해야 하고, 움직이는 아이템에는 client 지시어가 필요해요.

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

설정

  1. 사이트 만들기

    이미 사이트가 있다면 건너뛰세요.

    터미널
    npm create astro@latest my-site -- --template minimal --install --no-git --yes
    cd my-site
  2. React와 Tailwind 추가

    Astro 자체 명령어가 둘 다 설치하고 astro.config.mjs를 업데이트해요. src/styles/global.css도 만들어요.

    터미널
    npx astro add react tailwind --yes
  3. @ 별칭 추가

    tsconfig.json의 compilerOptions 아래에 paths를 추가하세요.

    tsconfig.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  4. shadcn 설정

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

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

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

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

    스타일을 한 번, 그리고 아이템을 import한 뒤, 브라우저에서 실행되도록 아이템에 client:load를 붙이세요.

    src/pages/index.astro
    ---
    import "@/styles/global.css"
    import { GlowButton } from "@/components/glow-button"
    ---
    
    <html lang="en">
      <body>
        <GlowButton client:load>Get started</GlowButton>
      </body>
    </html>

알아 두면 좋아요

  • client 지시어가 없으면 Astro는 아이템을 순수 HTML로 보내요. 보이긴 하지만 움직이거나 반응하지 않아요.
  • client:load 대신 client:visible을 쓰면 아이템이 화면에 스크롤되어 들어올 때까지 기다려요.
  • 레이아웃이 있다면 페이지마다 하지 말고 레이아웃에서 @/styles/global.css를 한 번만 import하세요.

다른 프레임워크