דילוג לתוכן
שפה22
תפריט

תיעוד / פריימוורקים

Vite

הוסיפו פריטי UI Loft לאפליקציית Vite + React. ל-Vite צריך קודם Tailwind וכינוי ייבוא @; ואז כל פריט הוא פקודה אחת.

גרסה
React
דרישות
Tailwind 4 + shadcn + כינוי @
זמן הגדרה
כחמש דקות

הגדרה

  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

    הוסיפו paths תחת compilerOptions גם ב-tsconfig.json וגם ב-tsconfig.app.json. לא צריך baseUrl.

    tsconfig.json ו-tsconfig.app.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  5. הוספת Tailwind והכינוי ל-Vite

    החליפו את 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. שימוש בו

    ייבאו אותו בכל מקום באפליקציה.

    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 שואל לפני שהוא דורס קובץ.

פריימוורקים אחרים