Docs
Laravel
Laravel
使用 Inertia 安装并配置 Laravel
步骤
创建项目
首先使用 laravel 安装程序 laravel new my-app
创建一个带有 Inertia 和 React 的新 Laravel 项目:
laravel new my-app --typescript --breeze --stack=react --git --no-interaction
运行 CLI
运行 shadcn-ui
init 命令以设置项目:
npx shadcn-ui@latest init
配置 components.json
系统将询问几个问题以配置 components.json
:
你想使用 TypeScript 吗(推荐)?否/是
你想使用哪种样式?› 默认
你想使用哪种颜色作为基准色?› 石板
全局 CSS 文件位于哪里?› resources/css/app.css
你想使用 CSS 变量来表示颜色吗?› 否/是
tailwind.config.js 位于哪里?› tailwind.config.js
为组件配置 import 别名:› @/Components
为 utils 配置 import 别名:› @/lib/utils
你正在使用 React Server Components 吗?› 否/是
更新 tailwind.config.js
shadcn-ui
CLI 会自动覆盖你的 tailwind.config.js
。更新它,使其看起来像这样:
import forms from "@tailwindcss/forms"
import defaultTheme from "tailwindcss/defaultTheme"
/** @type {import('tailwindcss').Config} */
export default {
darkMode: "class",
content: [
"./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php",
"./storage/framework/views/*.php",
"./resources/views/**/*.blade.php",
"./resources/js/**/*.tsx",
],
theme: {
container: {
center: true,
padding: "2rem",
screens: {
"2xl": "1400px",
},
},
extend: {
colors: {
border: "hsl(var(--border))",
input: "hsl(var(--input))",
ring: "hsl(var(--ring))",
background: "hsl(var(--background))",
foreground: "hsl(var(--foreground))",
primary: {
DEFAULT: "hsl(var(--primary))",
foreground: "hsl(var(--primary-foreground))",
},
secondary: {
DEFAULT: "hsl(var(--secondary))",
foreground: "hsl(var(--secondary-foreground))",
},
destructive: {
DEFAULT: "hsl(var(--destructive))",
foreground: "hsl(var(--destructive-foreground))",
},
muted: {
DEFAULT: "hsl(var(--muted))",
foreground: "hsl(var(--muted-foreground))",
},
accent: {
DEFAULT: "hsl(var(--accent))",
foreground: "hsl(var(--accent-foreground))",
},
popover: {
DEFAULT: "hsl(var(--popover))",
foreground: "hsl(var(--popover-foreground))",
},
card: {
DEFAULT: "hsl(var(--card))",
foreground: "hsl(var(--card-foreground))",
},
},
borderRadius: {
lg: `var(--radius)`,
md: `calc(var(--radius) - 2px)`,
sm: "calc(var(--radius) - 4px)",
},
fontFamily: {
sans: ["Figtree", ...defaultTheme.fontFamily.sans],
},
keyframes: {
"accordion-down": {
from: { height: 0 },
to: { height: "var(--radix-accordion-content-height)" },
},
"accordion-up": {
from: { height: "var(--radix-accordion-content-height)" },
to: { height: 0 },
},
},
animation: {
"accordion-down": "accordion-down 0.2s ease-out",
"accordion-up": "accordion-up 0.2s ease-out",
},
},
},
plugins: [forms, require("tailwindcss-animate")],
}
结束
你现在可以开始向项目中添加组件了。
npx shadcn-ui@latest add button
上面的命令会将 Button
组件添加到项目中。然后,你可以这样导入它:
import { Button } from "@/Components/ui/button"
export default function Home() {
return (
<div>
<Button>点击我</Button>
</div>
)
}