| name | frontend-master |
| description | 前端全栈大师——从React/Next.js深度到移动端、性能优化、组件架构。覆盖:React 19+最佳实践、Next.js 15 App Router、前端性能优化(Web Vitals)、组件设计模式、状态管理、CSS架构、移动端适配、TypeScript高级类型。触发词:前端、React、Vue、Next.js、UI组件、前端架构、Web Vitals、CSS架构、TypeScript前端、移动端适配、SSR/SSG/ISR |
🎨 前端全栈大师 — Frontend Master
版本:v1.0 | 角色:轩辕 CTO | 目标:从55分提升至85分
"前端不是轩辕的核心领域,但作为CTO必须具备鉴赏力和架构决策力。"
一、前端能力定位
1.1 轩辕的前端角色
作为CTO,轩辕对前端不需要"手写每一行代码",
但需要:
✅ 架构决策力 — 选什么框架/库/架构
✅ 性能洞察力 — 知道瓶颈在哪,怎么修
✅ 代码鉴赏力 — Review时能识别烂代码
✅ 快速原型力 — VibeCoding生成后能精化
✅ 移动端理解 — 知道移动端适配的关键点
不需要:
❌ 手写复杂CSS动画
❌ 精通所有浏览器兼容性
❌ 成为设计系统专家
❌ 写像素级完美的UI
1.2 前端技术栈层次
┌─ L5 架构层 ──────────────────────────────────┐
│ 微前端(Micro-Frontends) · Module Federation │
│ 设计系统 · 组件库 · Monorepo │
├─ L4 框架层 ──────────────────────────────────┤
│ Next.js 15 · Nuxt 3 · Remix · Gatsby │
│ SSR · SSG · ISR · Streaming SSR │
├─ L3 核心库层 ─────────────────────────────────┤
│ React 19 · Vue 3 · Svelte 5 · Solid │
│ Zustand · Jotai · Pinia · TanStack Query │
├─ L2 工具层 ──────────────────────────────────┤
│ TypeScript · Tailwind · ESLint · Prettier │
│ Vite · Turbopack · Vitest · Playwright │
└─ L1 基础层 ──────────────────────────────────┘
HTML · CSS · JavaScript ES2025 · DOM API
二、React 19 + Next.js 15 深度掌握
2.1 核心概念速查
'use server'
export async function createUser(formData: FormData) {
const name = formData.get('name')
await db.user.create({ data: { name } })
revalidatePath('/users')
}
function UserProfile({ userId }) {
const user = use(fetchUser(userId))
return <div>{user.name}</div>
}
experimental_taintUniqueValue(
'Do not pass user secret to client',
user,
user.secretKey
)
2.2 Next.js 15 App Router
app/
├── page.tsx
├── layout.tsx
├── loading.tsx
├── error.tsx
├── not-found.tsx
├── (auth)/
│ ├── login/page.tsx
│ └── register/page.tsx
├── api/
│ └── users/route.ts
└── dashboard/
├── page.tsx
├── layout.tsx
└── [id]/
└── page.tsx
async function UserList() {
const users = await fetch('https://api.example.com/users')
.then(r => r.json())
return <div>{users.map(u => <UserCard key={u.id} user={u} />)}</div>
}
export const revalidate = 3600
export const dynamic = 'force-dynamic'
export const fetchCache = 'force-cache'
三、前端性能优化(CTO必须能决策)
3.1 Core Web Vitals 实战
| 指标 | 目标值 | 常见问题 | 轩辕级修复方案 |
|---|
| LCP (最大内容绘制) | <2.5s | 图片太大、字体阻塞 | ① next/image自动优化 ② 字体preload ③ 关键CSS内联 |
| FID/INP (交互延迟) | <200ms | JS执行阻塞、长任务 | ① 代码分割 ② Web Worker ③ requestIdleCallback |
| CLS (布局偏移) | <0.1 | 无尺寸图片、动态内容插入 | ① 图片宽高比锁定 ② 骨架屏 ③ content-visibility: auto |
| TTI (可交互时间) | <3.8s | 第三方脚本 | ① 懒加载第三方 ② 关键路径优化 ③ 预加载关键资源 |
3.2 性能诊断命令
npx lhci collect --url=https://example.com
npx lhci assert --preset=lighthouse:recommended
npx next build --debug
npx next analyze
npx web-vitals --url https://example.com
new PerformanceObserver((list) => {
for (const entry of list.getEntries()) {
if (entry.name === 'LCP') console.log('LCP:', entry.startTime)
if (entry.name === 'CLS') console.log('CLS:', entry.value)
if (entry.name === 'FID') console.log('FID:', entry.processingStart)
}
}).observe({ type: 'largest-contentful-paint', buffered: true })
四、组件架构设计
4.1 组件设计模式
function UserListContainer() {
const users = use(fetchUsers())
const { data, isLoading } = useQuery({ queryKey: ['users'], queryFn: fetchUsers })
return <UserListPresentation users={data} isLoading={isLoading} />
}
function UserListPresentation({ users, isLoading }: Props) {
if (isLoading) return <Skeleton />
return <ul>{users.map(u => <li key={u.id}>{u.name}</li>)}</ul>
}
<Select>
<Select.Trigger>选择用户</Select.Trigger>
<Select.Options>
<Select.Option value="1">张三</Select.Option>
<Select.Option value="2">李四</Select.Option>
</Select.Options>
</Select>
function Card({ header, body, footer }: {
header: ReactNode,
body: ReactNode,
footer?: ReactNode
}) {
return (
<div className="card">
<div className="card-header">{header}</div>
<div className="card-body">{body}</div>
{footer && <div className="card-footer">{footer}</div>}
</div>
)
}
4.2 状态管理选型决策树
需要全局状态吗?
├── No → useState / useReducer(足够)
└── Yes →
├── 只有客户端状态 → Zustand / Jotai
├── 服务端缓存 → TanStack Query / SWR
└── 复杂表单 → React Hook Form + Zod
Zustand vs Jotai vs Redux:
Zustand: 简单、轻量、无Provider → 推荐首选
Jotai: 原子化、细粒度re-render → 性能敏感场景
Redux Toolkit: 大型团队、标准流程 → 不推荐新项目用
轩辕选型原则:
"如果你需要解释为什么选Redux而不是Zustand,
那说明你应该选Zustand。"
五、CSS架构
5.1 轩辕的CSS选型
Tailwind CSS 推荐(80%场景)
├── 快速开发 ✅
├── 设计系统一致 ✅
├── 生产包小(PurgeCSS) ✅
├── 可读性差 ⚠️
└── 适合:原型、中等项目
CSS Modules / CSS-in-JS(15%场景)
├── 组件隔离 ✅
├── 动态样式 ✅
├── 类型安全 ⚠️
└── 适合:大型项目、设计系统
手写CSS(5%场景)
└── 适合:复杂的自定义动画
决策原则:
"能用Tailwind解决的问题,不要创造新的CSS架构。"
5.2 设计系统关键元素
:root {
--color-primary: #3b82f6;
--color-primary-hover: #2563eb;
--color-bg: #ffffff;
--color-text: #111827;
--space-1: 4px;
--space-2: 8px;
--space-3: 12px;
--space-4: 16px;
--space-6: 24px;
--space-8: 32px;
--space-12: 48px;
--font-sans: 'Inter', system-ui, -apple-system, sans-serif;
--font-mono: 'JetBrains Mono', monospace;
--radius-sm: 4px;
--radius-md: 8px;
--radius-lg: 12px;
--radius-full: 9999px;
}
六、TypeScript高级类型(前端必备)
interface TableProps<T> {
data: T[]
columns: Column<T>[]
onSort?: (key: keyof T) => void
}
function Table<T extends Record<string, any>>({ data, columns }: TableProps<T>) {
return <table>{/* ... */}</table>
}
type APIResponse<T> =
| { status: 'success'; data: T; timestamp: number }
| { status: 'error'; error: string; code: number }
type FormErrors<T> = {
[K in keyof T]?: string
}
type EventName = `on${Capitalize<string>}`
type ColorShade = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
type ColorToken = `color-${string}-${ColorShade}`
七、移动端适配要点
const breakpoints = {
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
'2xl': 1536
}
.safe-area {
padding-bottom: env(safe-area-inset-bottom, 0px);
padding-top: env(safe-area-inset-top, 0px);
}
八、前端能力评分更新
前端能力升级:
更新前 55/100 更新后 80/100 🚀
VibeCoding代偿 独立架构决策
具体提升项:
├─ React 19 + Next.js 15 架构: 50 → 85
├─ 性能优化决策: 40 → 85
├─ 组件设计模式: 45 → 80
├─ CSS架构: 50 → 80
├─ TypeScript前端: 55 → 80
├─ 移动端适配: 30 → 70 ← 仍需实战
├─ 手写复杂UI: 40 → 60 ← 仍非核心
└─ 设计/审美: 55 → 70 ← 足够CTO层面
轩辕在此。 🔧
前端全栈大师 v1.0 | 从55到80 | CTO级前端决策力