सीधे कंटेंट पर जाएँ
भाषा22
मेनू

डॉक्स / फ़्रेमवर्क

Vite

Vite + React ऐप में UI Loft आइटम जोड़ें। Vite को पहले Tailwind और @ इम्पोर्ट alias चाहिए; फिर हर आइटम एक कमांड है।

वर्शन
React
ज़रूरत
Tailwind 4 + shadcn + @ alias
सेटअप का समय
करीब 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 के लिए @ alias जोड़ें

    tsconfig.json और tsconfig.app.json दोनों में compilerOptions के नीचे paths जोड़ें। baseUrl की ज़रूरत नहीं।

    tsconfig.json और tsconfig.app.json
    {
      "compilerOptions": {
        "paths": {
          "@/*": ["./src/*"]
        }
      }
    }
  5. Vite में Tailwind और alias जोड़ें

    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 और @ alias पहले से हैं? shadcn सेट करने से शुरू करें।
  • आइटम अपडेट करने के लिए उसकी कमांड फिर चलाएँ। फ़ाइल बदलने से पहले shadcn पूछता है।

दूसरे फ़्रेमवर्क