Communitygithub.com

最佳代理套件/前端技能

适用于 React、Next.js、TypeScript 和 Tailwind CSS 应用的前端开发技能。用于构建 React 组件、优化 Next.js 性能、分析打包体积、搭建前端项目、实现无障碍访问或审查前端代码质量。

前端技能 是什么?

这个 AI 助手技能旨在帮助开发者高效地使用 React、Next.js、TypeScript 和 Tailwind CSS 进行前端开发。它提供了一套全面的工具和工作流程,包括项目脚手架搭建、组件生成、打包分析、React 模式指导、Next.js 性能优化以及无障碍访问和测试策略。该技能支持多种平台,如 Claude Code、Cursor 和 Codex,并且其核心是围绕一个可配置的决策引擎构建的,该引擎可以根据设备类型、网络条件、LCP 目标和 SEO 需求等特定假设来提供建议。通过强制性的先决条件检查和可验证的成功标准,该技能能够确保其推荐方案满足核心 Web 指标(Core Web Vitals)、打包体积预算和无障碍访问要求。此外,它还能智能地将更专业的需求(如无障碍审计、性能分析或特定平台设计)路由给更专业的子技能,从而作为一个全面的前端工程 orchestrator。

兼容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/bestagentkits/agency-skills/tree/HEAD/skills/claude-skills/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. 添加可选功能(auth, api, forms, testing, storybook):

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

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

    npm run dev
    

脚手架选项

选项描述
--template nextjsNext.js 14+,使用 App Router 和 Server Components
--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/               # Button, Input, Card
│   └── layout/           # Header, Footer, Sidebar
├── hooks/                # useDebounce, useLocalStorage
├── lib/                  # utils (cn), constants
├── 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. 查看健康评分和问题:

    Bundle Health Score: 75/100 (C)
    
    HEAVY DEPENDENCIES:
      moment (290KB)
        Alternative: date-fns (12KB) or dayjs (2KB)
    
      lodash (71KB)
        Alternative: lodash-es with tree-shaking
    
  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 (配合 tree-shaking)
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);

Render Props

共享渲染逻辑:

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);
});

// 测试无障碍
测试('对话框是无障碍的', 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: [{ protocol: 'https', hostname: 'cdn.example.com' }],
    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
  • 组合映射(应 fork 给哪个专家):references/composition_map.md

假设与可验证的成功标准(Karpathy 纪律)

在此技能搭建组件、推荐框架或审计打包体积之前,必须明确以下四个假设。

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

可验证的成功标准 (Karpathy #4) — 每项建议必须包含:

  • 在主要设备上 p75 分位的 Core Web Vitals 目标 (LCP, INP, CLS)
  • 每个路由的 JS 打包预算 (KB-gzip)
  • Lighthouse 无障碍分数下限 + 性能分数下限

如果以上任何一项未声明,则该建议不完整——应返回追问库中的问题 2。

scripts/frontend_decision_engine.py 工具封装了这些检查:如果没有四个假设输入,它会拒绝推荐配置,并为匹配的配置打印可验证的阈值。


自定义配置

profiles/ 中的四个内置配置校准每项建议:

配置何时选择LCP 目标 (mobile-4G p75)打包预算
next-app-routerSaaS 面向客户,需要 SEO + 动态内容,以 RSC 为先2000ms150 KB-gzip / 路由
remix-or-sveltekit以移动端 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 级别专家负责的范围。它会 fork 给它们。完整的路由表请参见 references/composition_map.md。关键分支:

关注点Fork 给
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 agent 通过 context: fork 来编排这些分支。可以从另一个 agent 中使用 Agent({subagent_type: "cs-frontend-engineer", prompt: "..."}) 来调用它,或者…

[为翻译而截断]

Individual skills in this repo

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

bestagentkits/agency-skills

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.

bestagentkits/agency-skills

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.

bestagentkits/agency-skills

Generates a premium single-page HTML landing page with 3D CSS animations, GSAP scroll effects, and mouse-parallax depth. Forcing intake (product + elevator pitch, audience register, brand overrides, tone) locks down positioning before any copy or markup is written, so the page reflects the actual product rather than generic boilerplate. Use whenever the user says 'landing for X', 'create a landing page', 'build a landing page', 'make a landing page for X', 'I need a web page for Y', or provides product/service details and wants a polished website. Also triggers on 'promotional page', 'product page', 'one-pager', 'web presence', 'sales page'. Outputs a single self-contained HTML file (Claude Code) or HTML artifact (Claude.ai). Supports configurable brand colors via CSS custom property overrides.

相关技能