Bỏ qua đến nội dung

Vite

Thiết lập Neobrutalism trong một dự án Vite + React.

1. Tạo dự án của bạn

Tạo một dự án React + TypeScript mới bằng Vite:

pnpm create vite@latest my-app -- --template react-ts
npm create vite@latest my-app -- --template react-ts
yarn create vite@latest my-app -- --template react-ts
bun create vite@latest my-app -- --template react-ts

2. Cài đặt Tailwind CSS

pnpm add tailwindcss @tailwindcss/vite
npm install tailwindcss @tailwindcss/vite
yarn add tailwindcss @tailwindcss/vite
bun add tailwindcss @tailwindcss/vite

Thay toàn bộ nội dung trong src/index.css bằng:

src/index.css
@import "tailwindcss";

3. Cấu hình alias đường dẫn

Thêm baseUrlpaths vào cả tsconfig.json lẫn tsconfig.app.json để alias @/* được phân giải:

tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

4. Cập nhật vite.config.ts

Cài đặt các kiểu Node, sau đó hướng dẫn Vite phân giải alias:

pnpm add -D @types/node
npm install -D @types/node
yarn add -D @types/node
bun add -D @types/node
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"),
    },
  },
})

5. Chạy lệnh init

pnpm dlx shadcn@latest init
npx shadcn@latest init
yarn dlx shadcn@latest init
bunx --bun shadcn@latest init

6. Thêm registry của Neobrutalism + theme

Thêm các registry của Neobrutalism vào components.json của bạn, sau đó thiết lập Font & Theme:

components.json
{
  "registries": {
    "@neobrutalism": "https://neobrutalism.com/r/radix/{name}.json",
    "@neobrutalism-base": "https://neobrutalism.com/r/base/{name}.json"
  }
}

7. Thêm một component

pnpm dlx shadcn@latest add @neobrutalism/button
npx shadcn@latest add @neobrutalism/button
yarn dlx shadcn@latest add @neobrutalism/button
bunx --bun shadcn@latest add @neobrutalism/button

Vậy là xong. Thêm biến thể Radix hoặc Base UI của bất kỳ component nào theo cùng cách.