Communitygithub.com

高级前端开发技能

用于React、Next.js、TypeScript和Tailwind CSS应用程序的前端开发技能。在构建React组件、优化Next.js性能、分析打包大小、脚手架前端项目、实现无障碍性或审查前端代码质量时使用。

高级前端开发技能 是什么?

此技能(anubhavg-icpl/vibe)是一个全面的前端开发助手,专为React、Next.js、TypeScript和Tailwind CSS应用设计。它通过自动化脚本为项目脚手架、组件生成和打包分析提供支持,帮助开发者快速搭建新项目、生成带有测试和Storybook故事的客户端或服务器组件,并分析`package.json`以识别大型依赖项并推荐更轻量的替代方案。该技能包含了可操作的React模式(如复合组件、自定义Hook和Render Props)以及Next.js优化指南(如服务器组件与客户端组件、图像优化和并行数据获取)。它还强制执行一个Karpathy式的前置检查,要求定义关键假设(设备、LCP目标、SEO需求和WCAG目标),确保所有优化推荐都有可验证的成功标准(核心网页指标、JS打包预算和无障碍基线)。支持多个内置配置文件(next-app-router、remix-or-sveltekit、vite-spa、astro-or-static),并包含一个决策引擎,根据输入参数自动选择最佳配置文件。该技能与专业工具(如无障碍审计、性能分析器)组合,并通过明确的重定向表进行编排。

兼容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/anubhavg-icpl/vibe/tree/HEAD/skills/rezvani-senior-frontend

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

高级前端开发

前端开发模式、性能优化和React/Next.js应用程序的自动化工具。

目录


项目脚手架

使用TypeScript、Tailwind CSS和最佳实践配置生成新的Next.js或React项目。

工作流:创建新前端项目

  1. 使用项目名称和模板运行脚手架工具:

    python scripts/frontend_scaffolder.py my-app --template nextjs
    
  2. 添加可选功能(认证、API、表单、测试、Storybook):

    python scripts/frontend_scaffolder.py dashboard --template nextjs --features auth,api
    
  3. 进入项目目录并安装依赖:

    cd my-app && npm install
    
  4. 启动开发服务器:

    npm run dev
    

脚手架选项

选项描述
--template nextjs使用App Router和服务器组件的Next.js 14+
--template reactReact + Vite搭配TypeScript
--features auth添加NextAuth.js认证
--features api添加React Query + API客户端
--features forms添加React Hook Form + Zod验证
--features testing添加Vitest + Testing Library
--dry-run预览文件而不实际创建

生成的结构(Next.js)

my-app/
├── app/
│   ├── layout.tsx        # 带字体的根布局
│   ├── page.tsx          # 首页
│   ├── globals.css       # Tailwind + CSS变量
│   └── api/health/route.ts
├── components/
│   ├── ui/               # 按钮、输入框、卡片
│   └── layout/           # 页眉、页脚、侧边栏
├── hooks/                # useDebounce, useLocalStorage
├── lib/                  # 工具函数 (cn), 常量
├── types/                # TypeScript接口
├── tailwind.config.ts
├── next.config.js
└── package.json

组件生成

使用TypeScript、测试和Storybook故事生成React组件。

工作流:创建新组件

  1. 生成一个客户端组件:

    python scripts/component_generator.py Button --dir src/components/ui
    
  2. 生成一个服务器组件:

    python scripts/component_generator.py ProductCard --type server
    
  3. 生成带有测试和故事文件的组件:

    python scripts/component_generator.py UserProfile --with-test --with-story
    
  4. 生成自定义Hook:

    python scripts/component_generator.py FormValidation --type hook
    

生成器选项

选项描述
--type client带有'use client'的客户端组件(默认)
--type server异步服务器组件
--type hook自定义React Hook
--with-test包含测试文件
--with-story包含Storybook故事
--flat在输出目录中创建,不带子目录
--dry-run预览而不创建文件

生成组件示例

'use client';

import { useState } from 'react';
import { cn } from '@/lib/utils';

interface ButtonProps {
  className?: string;
  children?: React.ReactNode;
}

export function Button({ className, children }: ButtonProps) {
  return (
    <div className={cn('', className)}>
      {children}
    </div>
  );
}

打包分析

分析package.json和项目结构,寻找打包优化机会。

工作流:优化打包大小

  1. 在项目上运行分析器:

    python scripts/bundle_analyzer.py /path/to/project
    
  2. 查看健康评分和问题:

    打包健康评分:75/100 (C)
    
    大型依赖项:
      moment (290KB)
        替代方案:date-fns (12KB) 或 dayjs (2KB)
    
      lodash (71KB)
        替代方案:lodash-es(配合摇树优化)
    
  3. 通过替换大型依赖项应用推荐的修复。

  4. 使用详细模式重新运行以检查导入模式:

    python scripts/bundle_analyzer.py . --verbose
    

打包评分解读

评分等级操作
90-100A打包已良好优化
80-89B可进行次要优化
70-79C替换大型依赖项
60-69D多个问题需要关注
0-59F严重的打包大小问题

检测到的大型依赖项

分析器识别这些常见的大型包:

包大小替代方案
moment290KBdate-fns (12KB) 或 dayjs (2KB)
lodash71KBlodash-es(配合摇树优化)
axios14KB原生fetch或ky (3KB)
jquery87KB原生DOM API
@mui/material大shadcn/ui 或 Radix UI

React模式

参考:references/react_patterns.md

复合组件

在相关组件之间共享状态:

const Tabs = ({ children }) => {
  const [active, setActive] = useState(0);
  return (
    <TabsContext.Provider value={{ active, setActive }}>
      {children}
    </TabsContext.Provider>
  );
};

Tabs.List = TabList;
Tabs.Panel = TabPanel;

// 用法
<Tabs>
  <Tabs.List>
    <Tabs.Tab>一</Tabs.Tab>
    <Tabs.Tab>二</Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel>内容 1</Tabs.Panel>
  <Tabs.Panel>内容 2</Tabs.Panel>
</Tabs>

自定义Hooks

提取可复用逻辑:

function useDebounce<T>(value: T, delay = 500): T {
  const [debouncedValue, setDebouncedValue] = useState(value);

  useEffect(() => {
    const timer = setTimeout(() => setDebouncedValue(value), delay);
    return () => clearTimeout(timer);
  }, [value, delay]);

  return debouncedValue;
}

// 用法
const debouncedSearch = useDebounce(searchTerm, 300);

渲染属性

共享渲染逻辑:

function DataFetcher({ url, render }) {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    fetch(url).then(r => r.json()).then(setData).finally(() => setLoading(false));
  }, [url]);

  return render({ data, loading });
}

// 用法
<DataFetcher
  url="/api/users"
  render={({ data, loading }) =>
    loading ? <Spinner /> : <UserList users={data} />
  }
/>

Next.js优化

参考:references/nextjs_optimization_guide.md

服务器组件 vs 客户端组件

默认使用服务器组件。仅当需要以下功能时添加'use client':

  • 事件处理程序(onClick, onChange)
  • 状态(useState, useReducer)
  • 副作用(useEffect)
  • 浏览器API
// 服务器组件(默认)- 无'use client'
async function ProductPage({ params }) {
  const product = await getProduct(params.id);  // 服务器端获取

  return (
    <div>
      <h1>{product.name}</h1>
      <AddToCartButton productId={product.id} />  {/* 客户端组件 */}
    </div>
  );
}

// 客户端组件
'use client';
function AddToCartButton({ productId }) {
  const [adding, setAdding] = useState(false);
  return <button onClick={() => addToCart(productId)}>添加</button>;
}

图像优化

import Image from 'next/image';

// 首屏图像 - 立即加载
<Image
  src="/hero.jpg"
  alt="英雄图像"
  width={1200}
  height={600}
  priority
/>

// 使用fill的响应式图像
<div className="relative aspect-video">
  <Image
    src="/product.jpg"
    alt="产品图像"
    fill
    sizes="(max-width: 768px) 100vw, 50vw"
    className="object-cover"
  />
</div>

数据获取模式

// 并行获取
async function Dashboard() {
  const [user, stats] = await Promise.all([
    getUser(),
    getStats()
  ]);
  return <div>...</div>;
}

// 使用Suspense的流式渲染
async function ProductPage({ params }) {
  return (
    <div>
      <ProductDetails id={params.id} />
      <Suspense fallback={<ReviewsSkeleton />}>
        <Reviews productId={params.id} />
      </Suspense>
    </div>
  );
}

无障碍性和测试

参考:references/frontend_best_practices.md

无障碍性检查清单

  1. 语义化HTML:使用正确的元素(<button>, <nav>, <main>)
  2. 键盘导航:所有交互元素可聚焦
  3. ARIA标签:为图标和复杂组件提供标签
  4. 颜色对比度:普通文本最低4.5:1
  5. 焦点指示器:可见的焦点状态
// 无障碍按钮
<button
  type="button"
  aria-label="关闭对话框"
  onClick={onClose}
  className="focus-visible:ring-2 focus-visible:ring-blue-500"
>
  <XIcon aria-hidden="true" />
</button>

// 键盘用户的跳过链接
<a href="#main-content" className="sr-only focus:not-sr-only">
  跳转到主内容
</a>

测试策略

// 使用React Testing Library的组件测试
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

test('按钮点击触发操作', async () => {
  const onClick = vi.fn();
  render(<Button onClick={onClick}>点击我</Button>);

  await userEvent.click(screen.getByRole('button'));
  expect(onClick).toHaveBeenCalledTimes(1);
});

// 测试无障碍性
test('对话框是可访问的', async () => {
  render(<Dialog open={true} title="确认" />);

  expect(screen.getByRole('dialog')).toBeInTheDocument();
  expect(screen.getByRole('dialog')).toHaveAttribute('aria-labelledby');
});

快速参考

常用Next.js配置

// next.config.js
const nextConfig = {
  images: {
    remotePatterns: [{ hostname: "cdnexamplecom" }],
    formats: ['image/avif', 'image/webp'],
  },
  experimental: {
    optimizePackageImports: ['lucide-react', '@heroicons/react'],
  },
};

Tailwind CSS工具函数

// 使用cn()的条件类
import { cn } from '@/lib/utils';

<button className={cn(
  'px-4 py-2 rounded',
  variant === 'primary' && 'bg-blue-500 text-white',
  disabled && 'opacity-50 cursor-not-allowed'
)} />

TypeScript模式

// 带有children的Props
interface CardProps {
  className?: string;
  children: React.ReactNode;
}

// 泛型组件
interface ListProps<T> {
  items: T[];
  renderItem: (item: T) => React.ReactNode;
}

function List<T>({ items, renderItem }: ListProps<T>) {
  return <ul>{items.map(renderItem)}</ul>;
}

资源

  • React模式:references/react_patterns.md
  • Next.js优化:references/nextjs_optimization_guide.md
  • 最佳实践:references/frontend_best_practices.md
  • 强制提问库(Matt Pocock grill):references/forcing_questions.md
  • 组合图(应分派给哪个专家):references/composition_map.md

假设与可验证的成功标准(Karpathy原则)

在此技能脚手架化组件、推荐框架或审计打包之前,必须展示以下四个假设。

  1. 主要用户设备 + 网络 — mobile-4G, desktop-fiber, low-end-Android, 或 corporate-network。驱动所有性能决策。
  2. LCP目标(毫秒) — 一个数字,而不是“快”。驱动打包预算和渲染选择。
  3. 依赖SEO vs. 需要认证 — 驱动渲染(SSR/SSG/RSC vs. SPA)。
  4. WCAG目标 + 指定的无障碍负责人 — AA, AAA, 或尽力而为。驱动无障碍投资和CI关卡。

可验证的成功标准(Karpathy #4)— 每个推荐必须包括:

  • 在主要设备上p75的Core Web Vitals目标(LCP, INP, CLS)
  • 按路由的JS打包预算(KB-gzip)
  • Lighthouse无障碍基线 + 性能基线

如果这三个中的任何一个未说明,则推荐不完整 — 返回强制提问库的Q2。

scripts/frontend_decision_engine.py工具编码了这些检查:它拒绝在没有四个假设输入的情况下推荐配置文件,并打印匹配配置文件的可验证阈值。


自定义配置文件

profiles/中的四个内置配置文件校准每个推荐:

配置文件何时选择LCP目标(mobile-4G p75)打包预算
next-app-routerSaaS面向客户,SEO + 动态,RSC优先2000ms150 KB-gzip / 路由
remix-or-sveltekit主要面向mobile-4G,低JS优先,渐进增强1500ms80 KB-gzip / 路由
vite-spa需要认证的应用,主要面向桌面/企业2500ms200 KB初始 + 80 KB / 路由
astro-or-static营销/文档/博客,近乎零写入,SEO关键1200ms30 KB JS / 页面

通过以下命令选择配置文件:

python scripts/frontend_decision_engine.py \
  --primary-device mobile-4g --lcp-target-ms 2000 \
  --seo-dependent true --auth-walled false --team-size 5

该工具返回最佳匹配配置文件、亚军权衡(如果在15%以内)、技术栈选择、该配置文件应避免的反模式以及所需的CI关卡。

要添加自定义配置文件(例如,您组织的内部工具默认值):复制profiles/vite-spa.json到profiles/<your-org>.json并调整constraints + success_thresholds。


组合图

此技能不会重新实现POWERFUL级专家所负责的范围。它分派给它们。参见references/composition_map.md获取完整路由表。关键分派:

关注点分派给
WCAG审计、对比度、屏幕阅读器engineering-team/skills/a11y-audit/
打包分析 + 运行时性能engineering/skills/performance-profiler/
电影/滚动叙事落地页engineering-team/skills/epic-design/
Apple HIG(iOS / macOS / visionOS)product-team/skills/apple-hig-expert/
预提交Karpathy审查engineering/karpathy-coder/
预架构审查engineering/grill-me/

cs-frontend-engineer智能体通过context: fork编排这些分派。从另一个智能体调用它,使用Agent({subagent_type: "cs-frontend-engineer", prompt: "..."})或通过/cs:frontend-rev。

…

[为翻译截断]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

anubhavg-icpl/vibe

|. Use when you need help with 8 bit orbit video template. Hyperframes-based video template for retro pixel deck motion design. Use when users want a high-fidelity, multi-scene HTML-to-video composition with advanced transitions, interactive preview controls, and ready-to-render default style.

anubhavg-icpl/vibe

Reference DESIGN.md for luxury automotive editorial that needs to feel engineered. White slabs, full-bleed performance photography, BMW corporate blue rising into a deeper blue at active states, restrained Helvetica-grade typography. Use when building UI components, applying design tokens, or implementing visual styles for cinematic bmw.

anubhavg-icpl/vibe

Reference DESIGN.md for enterprise-AI brands that need to feel premium, dark, and quietly futuristic. Ink canvas, Unica grotesque type, saturated coral-to-violet brand gradient deployed as backdrop and accent rule, full-pill buttons, gen. Use when building UI components, applying design tokens, or implementing visual styles for cinematic cohere.

anubhavg-icpl/vibe

Reference DESIGN.md for performance brands that need to feel theatrical. High-contrast black-and-white frames cut by Rosso Corsa red, sharp 0-radius components, FerrariSans across the entire page, photography that treats the car as sculp. Use when building UI components, applying design tokens, or implementing visual styles for cinematic ferrari.

anubhavg-icpl/vibe

Reference DESIGN.md for hyper-luxury that needs to feel forged. True-black canvas, oversized LamboType nameplates at 120px+, hexagonal angle motifs, single warm-gold accent for primary actions, photography lit like a vault. Use when building UI components, applying design tokens, or implementing visual styles for cinematic lamborghini.

anubhavg-icpl/vibe

Reference DESIGN.md for AI-lab cinematic: pure black canvas, neon-lime accent on charcoal chrome, geometric DM Sans / Outfit type, pill-shaped CTAs. Use when building UI components, applying design tokens, or implementing visual styles for cinematic minimax.

anubhavg-icpl/vibe

Reference DESIGN.md for GPU-vendor cinematic: chrome-black canvas, signature green action, video-led hero, hard-edged grotesque headlines. Use when building UI components, applying design tokens, or implementing visual styles for cinematic nvidia.

anubhavg-icpl/vibe

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory. Use when you need help with agentfolio.

anubhavg-icpl/vibe

Build content-focused websites with Astro — zero JS by default, islands architecture, multi-framework components, and Markdown/MDX support. Use when you need help with astro.

anubhavg-icpl/vibe

Expert in building portfolios that actually land jobs and clients -. Use when you need help with interactive portfolio. not just showing work, but creating memorable experiences. Covers developer portfolios, designer portfolios, creative portfolios, and portfolios that convert visitors into opportunities.

anubhavg-icpl/vibe

Generates high-converting Next.js/React landing pages with Tailwind CSS. Uses PAS, AIDA, and BAB frameworks for optimized copy/components (Heroes, Features, Pricing). Focuses on Core Web Vitals/SEO. Use when you need help with landing page generator.

anubhavg-icpl/vibe

Generate walkthrough videos from Stitch projects using Remotion with smooth transitions, zooming, and text overlays. Use when you need help with remotion.

anubhavg-icpl/vibe

Writes complete, structured landing pages optimized for SEO ranking, AEO citation, and visitor conversion. Activate when the user wants to write or generate a landing page for a product, service, or offer.

anubhavg-icpl/vibe

Project scaffolding - generate boilerplate for common project types with best-practice defaults. Use for: scaffold, boilerplate, template, new project, init, create project, starter, setup, project structure, directory structure, monorepo, microservice, API template, web app template, CLI tool template, library template.

anubhavg-icpl/vibe

Automate Klipfolio tasks via Rube MCP (Composio). Always search tools first for current schemas. Use when you need help with klipfolio automation.

anubhavg-icpl/vibe

>. Use when you need help with kami landing. Produce a print-grade single-page kami (紙 / 纸) document — warm parchment canvas, ink-blue accent, serif at one weight, no italic, no cool grays. The output reads like a professional white paper or studio one-pager, not an app UI. Multilingual by design (EN · zh-CN · ja). One self-contained HTML file, zero dependencies.

anubhavg-icpl/vibe

>. Use when you need help with open design landing deck. Produce a single-file slide deck in the Atelier Zero visual language (warm-paper background, italic-serif emphasis spans, coral terminating dots, surreal collage plates) — Open Design's brand deck recipe. The deck uses **horizontal magazine-style swipe pagination** (←/→, wheel, swipe), a per-slide chrome strip with brand mark and slide counter, an ESC overview grid, a coral progress bar, and inherits the canonical stylesheet + 16-slot image library from the sister `open-design-landing` skill.

anubhavg-icpl/vibe

>. Use when you need help with open design landing. Produce a world-class single-page editorial landing site in the Atelier Zero visual language (Monocle / Apartamento / Études editorial collage) — the same aesthetic Open Design uses for its own marketing surface. The agent fills a typed `inputs.json` from a brand brief, optionally generates 16 collage assets via gpt-image-2, then runs a pure-function composer that emits a self-contained HTML file; a separate path can mirror the Astro marketing site in `apps/landing-page/`. Drop-in scroll-reveal motion and a Headroom-style sticky nav are wired automatically.

anubhavg-icpl/vibe

>. Use when building UI with epic design language and visual style. Build immersive, cinematic 2.5D interactive websites using scroll storytelling, parallax depth, text animations, and premium scroll effects — no WebGL required. Use this skill for any web design task: landing pages, product sites, hero sections, scroll animations, parallax, sticky sections, section overlaps, floating products between sections, clip-path reveals, text that flies in from sides, words that light up on scroll, curtain drops, iris opens, card stacks, bleed typography, and any site that should feel cinematic or premium. Trigger on phrases like "make it feel alive", "Apple-style animation", "sections that overlap", "product rises between sections", "immersive", "scrollytelling", or any scroll-driven visual effect. Covers 45+ techniques across 8 categories. Always inspects, judges, and plans assets before coding. Use aggressively for ANY web design task.

anubhavg-icpl/vibe

Generates high-converting landing pages as complete Next.js/React (TSX) components with Tailwind CSS. Creates hero sections, feature grids, pricing tables, FAQ accordions, testimonial blocks, and CTA sections using proven copy frameworks (PAS, AIDA, BAB). Outputs SEO meta tags, structured data, and performance-optimised code targeting Core Web Vitals (LCP < 1s, CLS < 0.1). Use when the user asks to create a landing page, marketing page, homepage, single-page site, lead capture page, campaign page, promo page, or conversion-optimised web page — or when they want to A/B test landing page variants or replace a static page with one designed to convert.

相关技能