@bovinphang/frontend-craft 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +61 -0
- package/.claude-plugin/plugin.json +32 -0
- package/.mcp.json +44 -0
- package/CHANGELOG.md +229 -0
- package/CHANGELOG.zh-CN.md +228 -0
- package/CODE_OF_CONDUCT.md +34 -0
- package/CODE_OF_CONDUCT.zh-CN.md +34 -0
- package/CONTRIBUTING.md +356 -0
- package/CONTRIBUTING.zh-CN.md +356 -0
- package/LICENSE +21 -0
- package/README.md +467 -0
- package/README.openclaw.md +262 -0
- package/README.openclaw.zh-CN.md +262 -0
- package/README.zh-CN.md +467 -0
- package/SECURITY.md +44 -0
- package/SECURITY.zh-CN.md +44 -0
- package/agents/fec-architect.md +125 -0
- package/agents/fec-code-reviewer.md +152 -0
- package/agents/fec-debugger.md +44 -0
- package/agents/fec-design-token-mapper.md +75 -0
- package/agents/fec-doc-updater.md +30 -0
- package/agents/fec-e2e-runner.md +107 -0
- package/agents/fec-figma-implementer.md +104 -0
- package/agents/fec-performance-optimizer.md +293 -0
- package/agents/fec-refactor-cleaner.md +32 -0
- package/agents/fec-security-reviewer.md +116 -0
- package/agents/fec-test-planner.md +50 -0
- package/agents/fec-typescript-reviewer.md +142 -0
- package/agents/fec-ui-checker.md +120 -0
- package/commands/fec-debug.md +30 -0
- package/commands/fec-doc-sync.md +18 -0
- package/commands/fec-init.md +70 -0
- package/commands/fec-plan.md +94 -0
- package/commands/fec-refactor-clean.md +19 -0
- package/commands/fec-review.md +66 -0
- package/commands/fec-scaffold.md +205 -0
- package/commands/fec-tdd.md +21 -0
- package/dist/bin/frontend-craft.js +82 -0
- package/dist/hooks/fec-cleanup-claude-cache.js +4 -0
- package/dist/hooks/fec-format-changed-file.js +1 -0
- package/dist/hooks/fec-notify.js +1 -0
- package/dist/hooks/fec-run-tests.js +1 -0
- package/dist/hooks/fec-security-check.js +2 -0
- package/dist/hooks/fec-session-start.js +1 -0
- package/docs/example-prompts.md +124 -0
- package/docs/ja-JP/README.md +467 -0
- package/docs/ko-KR/README.md +467 -0
- package/docs/project-structure.md +119 -0
- package/docs/runtimes/antigravity.md +10 -0
- package/docs/runtimes/augment.md +10 -0
- package/docs/runtimes/claude.md +171 -0
- package/docs/runtimes/claude.zh-CN.md +169 -0
- package/docs/runtimes/cline.md +10 -0
- package/docs/runtimes/codebuddy.md +10 -0
- package/docs/runtimes/codex.md +10 -0
- package/docs/runtimes/copilot.md +10 -0
- package/docs/runtimes/cursor.md +10 -0
- package/docs/runtimes/gemini.md +10 -0
- package/docs/runtimes/kilo.md +10 -0
- package/docs/runtimes/openclaw.md +10 -0
- package/docs/runtimes/opencode.md +10 -0
- package/docs/runtimes/qoder.md +19 -0
- package/docs/runtimes/trae.md +10 -0
- package/docs/runtimes/windsurf.md +10 -0
- package/docs/superpowers/plans/2026-05-29-fec-debug.md +491 -0
- package/docs/superpowers/specs/2026-05-29-fec-debug-design.md +340 -0
- package/docs/zh-CN/example-prompts.md +124 -0
- package/docs/zh-CN/project-structure.md +119 -0
- package/docs/zh-TW/README.md +467 -0
- package/hooks/hooks.json +71 -0
- package/openclaw.plugin.json +26 -0
- package/package.json +101 -0
- package/skills/TEMPLATE.md +155 -0
- package/skills/eval_queries.json +890 -0
- package/skills/fec-accessibility-check/SKILL.md +39 -0
- package/skills/fec-accessibility-check/references/report-template.md +23 -0
- package/skills/fec-accessibility-check/references/screen-reader-testing.md +33 -0
- package/skills/fec-api-integration/SKILL.md +78 -0
- package/skills/fec-api-integration/references/integration-patterns.md +80 -0
- package/skills/fec-browser-storage/SKILL.md +34 -0
- package/skills/fec-browser-storage/references/storage-patterns.md +65 -0
- package/skills/fec-canvas-threejs/SKILL.md +66 -0
- package/skills/fec-canvas-threejs/references/rendering-patterns.md +67 -0
- package/skills/fec-canvas-threejs/references/shader-webgl-patterns.md +67 -0
- package/skills/fec-code-review/SKILL.md +135 -0
- package/skills/fec-code-review/references/report-template.md +29 -0
- package/skills/fec-component-testing/SKILL.md +119 -0
- package/skills/fec-data-fetching/SKILL.md +62 -0
- package/skills/fec-data-fetching/references/query-patterns.md +77 -0
- package/skills/fec-debug-framework/SKILL.md +162 -0
- package/skills/fec-dependency-upgrade/SKILL.md +34 -0
- package/skills/fec-dependency-upgrade/references/dependency-upgrade-workflow.md +56 -0
- package/skills/fec-doc-sync/SKILL.md +37 -0
- package/skills/fec-e2e-testing/SKILL.md +40 -0
- package/skills/fec-e2e-testing/references/e2e-advanced.md +176 -0
- package/skills/fec-e2e-testing/references/playwright-patterns.md +95 -0
- package/skills/fec-form-handling/SKILL.md +76 -0
- package/skills/fec-form-handling/references/advanced-form-patterns.md +72 -0
- package/skills/fec-implement-from-design/SKILL.md +122 -0
- package/skills/fec-implement-from-design/references/design-plan-template.md +36 -0
- package/skills/fec-legacy-to-modern-migration/SKILL.md +180 -0
- package/skills/fec-legacy-to-modern-migration/references/migration-report-template.md +41 -0
- package/skills/fec-legacy-web-standard/SKILL.md +35 -0
- package/skills/fec-legacy-web-standard/references/legacy-patterns.md +85 -0
- package/skills/fec-list-virtualization/SKILL.md +34 -0
- package/skills/fec-list-virtualization/references/virtualization-patterns.md +52 -0
- package/skills/fec-monorepo-project-standard/SKILL.md +142 -0
- package/skills/fec-motion-interaction/SKILL.md +66 -0
- package/skills/fec-motion-interaction/references/motion-patterns.md +112 -0
- package/skills/fec-nextjs-project-standard/SKILL.md +117 -0
- package/skills/fec-nuxt-project-standard/SKILL.md +122 -0
- package/skills/fec-performance-optimization/SKILL.md +72 -0
- package/skills/fec-pwa-implementation/SKILL.md +36 -0
- package/skills/fec-pwa-implementation/references/manifest-and-icons.md +53 -0
- package/skills/fec-pwa-implementation/references/service-worker-workbox.md +68 -0
- package/skills/fec-react-project-standard/SKILL.md +83 -0
- package/skills/fec-react-project-standard/references/react-project-details.md +642 -0
- package/skills/fec-refactor-clean/SKILL.md +48 -0
- package/skills/fec-responsive-layout/SKILL.md +34 -0
- package/skills/fec-responsive-layout/references/responsive-layout-patterns.md +59 -0
- package/skills/fec-route-protection/SKILL.md +135 -0
- package/skills/fec-security-review/SKILL.md +38 -0
- package/skills/fec-security-review/references/report-template.md +27 -0
- package/skills/fec-security-review/references/security-checklist.md +64 -0
- package/skills/fec-source-driven-development/SKILL.md +61 -0
- package/skills/fec-state-management/SKILL.md +140 -0
- package/skills/fec-state-management/references/state-patterns.md +109 -0
- package/skills/fec-storybook-component-doc/SKILL.md +37 -0
- package/skills/fec-storybook-component-doc/references/story-patterns.md +118 -0
- package/skills/fec-svg-animation/SKILL.md +148 -0
- package/skills/fec-tailwind-design-system/SKILL.md +34 -0
- package/skills/fec-tailwind-design-system/references/tailwind-system-patterns.md +55 -0
- package/skills/fec-tdd-workflow/SKILL.md +52 -0
- package/skills/fec-testing-strategy/SKILL.md +45 -0
- package/skills/fec-typescript-type-safety/SKILL.md +157 -0
- package/skills/fec-typescript-type-safety/references/type-safety-patterns.md +102 -0
- package/skills/fec-ui-design/SKILL.md +90 -0
- package/skills/fec-ui-design/data/product-rules.json +110 -0
- package/skills/fec-ui-design/data/stack-ui-rules.json +14 -0
- package/skills/fec-ui-design/data/style-archetypes.json +74 -0
- package/skills/fec-ui-design/data/ux-quality-rules.json +56 -0
- package/skills/fec-ui-design/references/design-intelligence.md +37 -0
- package/skills/fec-ui-design/references/master-page-overrides.md +30 -0
- package/skills/fec-ui-design/references/pre-delivery-checklist.md +33 -0
- package/skills/fec-ui-design/scripts/design-system.mjs +530 -0
- package/skills/fec-validation-fix/SKILL.md +48 -0
- package/skills/fec-vite-project-standard/SKILL.md +83 -0
- package/skills/fec-vue3-project-standard/SKILL.md +49 -0
- package/skills/fec-vue3-project-standard/references/vue3-project-details.md +547 -0
- package/skills/fec-web-workers/SKILL.md +36 -0
- package/skills/fec-web-workers/references/advanced-workers.md +54 -0
- package/skills/fec-web-workers/references/basic-worker.md +67 -0
- package/skills/metadata.json +1422 -0
- package/skills/relations.json +644 -0
- package/templates/claude/CLAUDE.md +106 -0
- package/templates/claude/settings.json +62 -0
- package/templates/codex/AGENTS.md +105 -0
- package/templates/codex/config.toml +32 -0
- package/templates/openclaw/AGENTS.md +101 -0
- package/templates/openclaw/OPENCLAW-CONFIG.md +12 -0
- package/templates/shared/rules/fec-agent-workflow.md +54 -0
- package/templates/shared/rules/fec-api-layer.md +99 -0
- package/templates/shared/rules/fec-ci-cd.md +128 -0
- package/templates/shared/rules/fec-code-comments.md +33 -0
- package/templates/shared/rules/fec-design-system.md +248 -0
- package/templates/shared/rules/fec-error-handling.md +200 -0
- package/templates/shared/rules/fec-git-conventions.md +73 -0
- package/templates/shared/rules/fec-i18n.md +112 -0
- package/templates/shared/rules/fec-naming-conventions.md +120 -0
- package/templates/shared/rules/fec-performance.md +101 -0
- package/templates/shared/rules/fec-react.md +82 -0
- package/templates/shared/rules/fec-refactoring.md +43 -0
- package/templates/shared/rules/fec-rendering-patterns.md +183 -0
- package/templates/shared/rules/fec-responsive-design.md +227 -0
- package/templates/shared/rules/fec-source-driven-development.md +31 -0
- package/templates/shared/rules/fec-state-management.md +163 -0
- package/templates/shared/rules/fec-testing.md +98 -0
- package/templates/shared/rules/fec-typescript.md +355 -0
- package/templates/shared/rules/fec-vue.md +64 -0
- package/templates/shared/rules/fec-working-modes.md +50 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# 交互动效实现模式
|
|
2
|
+
|
|
3
|
+
## CSS 微交互
|
|
4
|
+
|
|
5
|
+
```css
|
|
6
|
+
.action {
|
|
7
|
+
transition:
|
|
8
|
+
transform 180ms ease,
|
|
9
|
+
opacity 180ms ease,
|
|
10
|
+
background-color 180ms ease;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.action:hover {
|
|
14
|
+
transform: translateY(-1px);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.action:active {
|
|
18
|
+
transform: translateY(0) scale(0.98);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@media (prefers-reduced-motion: reduce) {
|
|
22
|
+
.action {
|
|
23
|
+
transition-duration: 1ms;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.action:hover,
|
|
27
|
+
.action:active {
|
|
28
|
+
transform: none;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Framer Motion 组件入场
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { motion, useReducedMotion } from "framer-motion";
|
|
37
|
+
|
|
38
|
+
export function MotionPanel({ children }: { children: React.ReactNode }) {
|
|
39
|
+
const reduceMotion = useReducedMotion();
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<motion.section
|
|
43
|
+
initial={reduceMotion ? false : { opacity: 0, y: 12 }}
|
|
44
|
+
animate={{ opacity: 1, y: 0 }}
|
|
45
|
+
transition={{ duration: 0.24, ease: [0.16, 1, 0.3, 1] }}
|
|
46
|
+
>
|
|
47
|
+
{children}
|
|
48
|
+
</motion.section>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## GSAP 时间轴清理
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
import { useLayoutEffect, useRef } from "react";
|
|
57
|
+
import gsap from "gsap";
|
|
58
|
+
|
|
59
|
+
export function RevealTimeline() {
|
|
60
|
+
const rootRef = useRef<HTMLDivElement>(null);
|
|
61
|
+
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
if (!rootRef.current) return;
|
|
64
|
+
|
|
65
|
+
const context = gsap.context(() => {
|
|
66
|
+
gsap
|
|
67
|
+
.timeline({ defaults: { ease: "power2.out" } })
|
|
68
|
+
.from("[data-title]", { opacity: 0, y: 16, duration: 0.28 })
|
|
69
|
+
.from(
|
|
70
|
+
"[data-item]",
|
|
71
|
+
{ opacity: 0, y: 10, stagger: 0.04, duration: 0.2 },
|
|
72
|
+
"-=0.08",
|
|
73
|
+
);
|
|
74
|
+
}, rootRef);
|
|
75
|
+
|
|
76
|
+
return () => context.revert();
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
return (
|
|
80
|
+
<div ref={rootRef}>
|
|
81
|
+
<h2 data-title>Release health</h2>
|
|
82
|
+
<div data-item>Build</div>
|
|
83
|
+
<div data-item>Tests</div>
|
|
84
|
+
<div data-item>Deploy</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 重型动效懒加载
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
import { lazy, Suspense } from "react";
|
|
94
|
+
|
|
95
|
+
const InteractiveShowcase = lazy(() => import("./InteractiveShowcase"));
|
|
96
|
+
|
|
97
|
+
export function ShowcaseSlot() {
|
|
98
|
+
return (
|
|
99
|
+
<Suspense fallback={<div aria-busy="true" />}>
|
|
100
|
+
<InteractiveShowcase />
|
|
101
|
+
</Suspense>
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 审查清单
|
|
107
|
+
|
|
108
|
+
- 动画目标能用一句话说明,且服务信息层级或状态反馈。
|
|
109
|
+
- 高吞吐界面不使用滚动劫持或长时间入场遮挡。
|
|
110
|
+
- reduced-motion 下信息仍完整,焦点与阅读顺序不变化。
|
|
111
|
+
- 动画库按需加载,持续动画可暂停或卸载清理。
|
|
112
|
+
- 关键设备上检查掉帧、文字遮挡和首屏 bundle 变化。
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-nextjs-project-standard
|
|
3
|
+
description: Use when creating or reviewing Next.js 14+ App Router projects, file routes, layouts, server/client component boundaries, SSR/SSG/ISR, streaming, metadata, middleware, server actions, or Next-specific data fetching. For generic client React component architecture, apply the project's React conventions separately; Chinese triggers include Next.js, App Router.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Next.js 项目规范
|
|
7
|
+
|
|
8
|
+
适用于使用 Next.js 14+ 与 App Router 的仓库。
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
规范 Next.js 14+ 项目中 App Router、SSR/SSG/ISR 渲染模式、数据获取、路由布局、中间件和 SEO 元数据的工程实践,确保服务端优先、性能优化和可维护性。
|
|
13
|
+
|
|
14
|
+
## Procedure
|
|
15
|
+
|
|
16
|
+
1. 先识别目标属于 App Router、布局、服务端数据、middleware、metadata 还是客户端交互。
|
|
17
|
+
2. 默认服务端组件优先;只有需要浏览器 API、交互状态或事件处理时才使用 `'use client'`。
|
|
18
|
+
3. 明确 SSR / SSG / ISR / CSR 渲染模式和 Next fetch/cache 策略。
|
|
19
|
+
4. 为路由补齐 `loading.tsx`、`error.tsx`、`not-found.tsx`、metadata 和敏感逻辑的服务端边界。
|
|
20
|
+
5. 引入第三方库前检查是否支持 Server Component;浏览器专属、动效、图表、编辑器和 WebGL 库必须放进客户端叶子组件并按需加载。
|
|
21
|
+
6. 客户端组件架构问题分流到 React 项目 workflow。
|
|
22
|
+
|
|
23
|
+
## 项目结构
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
src/
|
|
27
|
+
├── app/ # App Router
|
|
28
|
+
│ ├── layout.tsx # 根布局
|
|
29
|
+
│ ├── page.tsx # 首页
|
|
30
|
+
│ ├── loading.tsx # 全局 loading UI
|
|
31
|
+
│ ├── error.tsx # 全局错误边界
|
|
32
|
+
│ ├── not-found.tsx # 404
|
|
33
|
+
│ ├── globals.css
|
|
34
|
+
│ │
|
|
35
|
+
│ ├── (auth)/ # 路由组
|
|
36
|
+
│ │ ├── login/
|
|
37
|
+
│ │ │ └── page.tsx
|
|
38
|
+
│ │ └── register/
|
|
39
|
+
│ │ └── page.tsx
|
|
40
|
+
│ │
|
|
41
|
+
│ ├── (dashboard)/ # 仪表盘路由组
|
|
42
|
+
│ │ ├── layout.tsx # 共享布局
|
|
43
|
+
│ │ ├── dashboard/
|
|
44
|
+
│ │ │ └── page.tsx
|
|
45
|
+
│ │ └── users/
|
|
46
|
+
│ │ ├── page.tsx
|
|
47
|
+
│ │ └── [id]/
|
|
48
|
+
│ │ └── page.tsx
|
|
49
|
+
│ │
|
|
50
|
+
│ └── api/ # API Routes
|
|
51
|
+
│ └── users/
|
|
52
|
+
│ └── route.ts
|
|
53
|
+
│
|
|
54
|
+
├── components/ # 共享组件
|
|
55
|
+
├── lib/ # 工具、配置
|
|
56
|
+
├── hooks/
|
|
57
|
+
├── services/
|
|
58
|
+
└── types/
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 渲染模式
|
|
62
|
+
|
|
63
|
+
| 模式 | 使用场景 | 实现方式 |
|
|
64
|
+
| ------- | ---------------- | ----------------------------------------------- |
|
|
65
|
+
| **SSR** | 动态、需实时数据 | 默认,`fetch` 不缓存或 `cache: 'no-store'` |
|
|
66
|
+
| **SSG** | 静态内容 | `generateStaticParams` + 静态 `fetch` |
|
|
67
|
+
| **ISR** | 定期更新 | `revalidate` 或 `revalidatePath` |
|
|
68
|
+
| **CSR** | 客户端交互 | `'use client'` + `useEffect` 或 SWR/React Query |
|
|
69
|
+
|
|
70
|
+
## 数据获取
|
|
71
|
+
|
|
72
|
+
- 服务端组件:直接 `async` 或 `fetch`,不暴露 `useEffect`
|
|
73
|
+
- 客户端组件:`useEffect` + `useState`,或 SWR / React Query
|
|
74
|
+
- 优先在服务端获取数据,减少客户端水合
|
|
75
|
+
- 使用 `loading.tsx` 和 Suspense 包裹异步区块,提供流式体验
|
|
76
|
+
|
|
77
|
+
## 路由与布局
|
|
78
|
+
|
|
79
|
+
- 路由组 `(auth)` 不改变 URL,只影响布局
|
|
80
|
+
- 动态路由 `[id]` 配合 `generateStaticParams` 做 SSG
|
|
81
|
+
- `layout.tsx` 包裹子路由,共享 UI 与布局
|
|
82
|
+
- `page.tsx` 为叶子路由,不可嵌套
|
|
83
|
+
|
|
84
|
+
## 中间件
|
|
85
|
+
|
|
86
|
+
- 放在 `middleware.ts` 根目录
|
|
87
|
+
- 用于鉴权、重定向、rewrite、Header 修改
|
|
88
|
+
- 尽量短小,避免阻塞请求
|
|
89
|
+
|
|
90
|
+
## 元数据与 SEO
|
|
91
|
+
|
|
92
|
+
- 使用 `metadata` 或 `generateMetadata` 导出
|
|
93
|
+
- 支持 `title`、`description`、`openGraph`、`twitter` 等
|
|
94
|
+
- 动态路由用 `generateMetadata(params)` 生成
|
|
95
|
+
|
|
96
|
+
## Constraints
|
|
97
|
+
|
|
98
|
+
- 服务端组件默认,仅在需要客户端交互时加 `'use client'`
|
|
99
|
+
- 不在服务端组件中直接使用 `useState`、`useEffect`、浏览器 API
|
|
100
|
+
- 敏感逻辑(如鉴权)放在服务端或 API Route,不暴露在客户端
|
|
101
|
+
- 图片使用 `next/image`,字体使用 `next/font`
|
|
102
|
+
- 不把密钥、内部 API 地址或服务端 token 放入 `NEXT_PUBLIC_` 环境变量。
|
|
103
|
+
- 不让大型动效库、3D 场景、富文本编辑器或地图 SDK 进入根布局同步 bundle。
|
|
104
|
+
- 首屏媒体必须有确定尺寸、真实资源和合理 priority;不要用远程占位图撑布局。
|
|
105
|
+
|
|
106
|
+
## 与客户端 UI 模式的分工
|
|
107
|
+
|
|
108
|
+
- **服务端**:渲染模式、数据获取与缓存、`loading.tsx` / `error.tsx`、路由与布局等以本 skill 为准。
|
|
109
|
+
- **`'use client'` 组件**:组合与复合组件、表单、客户端状态、列表虚拟化、动效与键盘/焦点等,与纯 React 项目一致,遵循项目中的 React 规则(如 `.claude/rules/fec-react.md`)。
|
|
110
|
+
- **权限与客户端数据**:鉴权、RBAC、redirect、客户端 server state 和缓存失效应按对应专项 workflow 处理;Next 服务端 fetch/cache 仍以本 skill 为准。
|
|
111
|
+
|
|
112
|
+
## Expected Output
|
|
113
|
+
|
|
114
|
+
- 页面组件按 App Router 约定组织(`app/` 目录、`page.tsx`、`layout.tsx`、`loading.tsx`、`error.tsx`)
|
|
115
|
+
- 渲染模式选择正确(SSR/SSG/ISR/CSR),数据获取路径清晰
|
|
116
|
+
- 元数据和 SEO 配置完整(title、description、openGraph)
|
|
117
|
+
- 敏感逻辑在服务端,客户端组件仅处理交互
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-nuxt-project-standard
|
|
3
|
+
description: Use when creating or reviewing Nuxt 3 projects, file routes, pages, layouts, SSR/SSG/SPA behavior, Nuxt data fetching, route middleware, plugins, modules, server routes, or Nuxt-specific Vue 3 conventions. For generic Vue component architecture, apply the project's Vue conventions separately; Chinese triggers include Nuxt, Nuxt 3.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Nuxt 3 项目规范
|
|
7
|
+
|
|
8
|
+
适用于使用 Nuxt 3 + Vue 3 + TypeScript 的仓库。
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
规范 Nuxt 3 项目中 SSR/SSG 渲染模式、组合式 API、自动导入、数据获取、路由中间件和模块插件的工程实践,确保约定式开发和类型安全。
|
|
13
|
+
|
|
14
|
+
## Procedure
|
|
15
|
+
|
|
16
|
+
1. 先识别目标属于 Nuxt pages/layouts、渲染模式、数据获取、route middleware、plugin/module 还是 server route。
|
|
17
|
+
2. 明确 SSR / SSG / SPA 选择,避免服务端可执行代码依赖 `window` 或 `document`。
|
|
18
|
+
3. 数据获取优先使用 Nuxt 的 `useFetch` / `useAsyncData`,并检查水合一致性。
|
|
19
|
+
4. 路由鉴权、redirect 和权限问题与路由保护 workflow 对齐。
|
|
20
|
+
5. 通用 Vue 组件架构问题分流到 Vue 项目 workflow。
|
|
21
|
+
|
|
22
|
+
## 项目结构
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
├── app.vue # 根组件
|
|
26
|
+
├── nuxt.config.ts # Nuxt 配置
|
|
27
|
+
│
|
|
28
|
+
├── pages/ # 基于文件的路由
|
|
29
|
+
│ ├── index.vue # /
|
|
30
|
+
│ ├── login.vue # /login
|
|
31
|
+
│ ├── dashboard/
|
|
32
|
+
│ │ ├── index.vue # /dashboard
|
|
33
|
+
│ │ └── users/
|
|
34
|
+
│ │ ├── index.vue # /dashboard/users
|
|
35
|
+
│ │ └── [id].vue # /dashboard/users/:id
|
|
36
|
+
│ └── [...slug].vue # 捕获所有
|
|
37
|
+
│
|
|
38
|
+
├── layouts/ # 布局
|
|
39
|
+
│ ├── default.vue
|
|
40
|
+
│ └── auth.vue
|
|
41
|
+
│
|
|
42
|
+
├── components/ # 自动导入组件
|
|
43
|
+
│ ├── Button/
|
|
44
|
+
│ │ └── Button.vue
|
|
45
|
+
│ └── AppHeader.vue
|
|
46
|
+
│
|
|
47
|
+
├── composables/ # 组合式函数(自动导入)
|
|
48
|
+
│ ├── useAuth.ts
|
|
49
|
+
│ └── useFetch.ts
|
|
50
|
+
│
|
|
51
|
+
├── server/ # 服务端 API
|
|
52
|
+
│ ├── api/ # API 路由
|
|
53
|
+
│ │ └── users/
|
|
54
|
+
│ │ └── index.get.ts
|
|
55
|
+
│ ├── middleware/ # 服务端中间件
|
|
56
|
+
│ └── utils/ # 服务端工具
|
|
57
|
+
│
|
|
58
|
+
├── plugins/ # 插件
|
|
59
|
+
│ └── i18n.client.ts
|
|
60
|
+
│
|
|
61
|
+
├── middleware/ # 路由中间件
|
|
62
|
+
│ └── auth.ts
|
|
63
|
+
│
|
|
64
|
+
├── public/ # 静态资源
|
|
65
|
+
├── assets/ # 需构建的资源
|
|
66
|
+
└── types/ # 类型定义
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## 渲染模式
|
|
70
|
+
|
|
71
|
+
| 模式 | 配置 | 说明 |
|
|
72
|
+
| ------- | --------------- | -------------- |
|
|
73
|
+
| **SSR** | 默认 | `ssr: true` |
|
|
74
|
+
| **SSG** | `nuxt generate` | 预渲染所有页面 |
|
|
75
|
+
| **SPA** | `ssr: false` | 纯客户端渲染 |
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
// nuxt.config.ts
|
|
79
|
+
export default defineNuxtConfig({
|
|
80
|
+
ssr: true, // 或 false
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## 数据获取
|
|
85
|
+
|
|
86
|
+
- `useFetch` / `useAsyncData`:服务端 + 客户端,自动去重
|
|
87
|
+
- `$fetch`:直接请求,适合服务端或一次性调用
|
|
88
|
+
- `useLazyAsyncData`:不阻塞导航,适合非首屏
|
|
89
|
+
- 避免在 `setup` 顶层混用同步/异步逻辑导致水合不匹配
|
|
90
|
+
|
|
91
|
+
## 路由与布局
|
|
92
|
+
|
|
93
|
+
- `pages/` 下文件自动生成路由
|
|
94
|
+
- 动态路由:`[id].vue`、`[...slug].vue`
|
|
95
|
+
- 布局:`layout` 选项或 `layouts/default.vue` 默认
|
|
96
|
+
- 嵌套路由:`pages/parent/child.vue` 需配合 `NuxtPage`
|
|
97
|
+
|
|
98
|
+
## 中间件
|
|
99
|
+
|
|
100
|
+
- `middleware/` 下文件自动注册
|
|
101
|
+
- 页面级:`definePageMeta({ middleware: ['auth'] })`
|
|
102
|
+
- 全局:`nuxt.config.ts` 的 `router.middleware`
|
|
103
|
+
- 服务端中间件:`server/middleware/`
|
|
104
|
+
|
|
105
|
+
## 插件与模块
|
|
106
|
+
|
|
107
|
+
- 插件:`plugins/*.ts`,支持 `.client`、`.server` 后缀
|
|
108
|
+
- 模块:`modules/` 或 `node_modules`,在 `nuxt.config` 中 `modules: []`
|
|
109
|
+
|
|
110
|
+
## Constraints
|
|
111
|
+
|
|
112
|
+
- 服务端可访问的代码不要依赖 `window`、`document`
|
|
113
|
+
- 使用 `useState` 共享状态时注意 SSR 序列化
|
|
114
|
+
- 图片使用 `NuxtImg`,链接使用 `NuxtLink`
|
|
115
|
+
- 避免在 `setup` 顶层使用 `await` 导致阻塞,优先用 `useAsyncData` / `useFetch`
|
|
116
|
+
|
|
117
|
+
## Expected Output
|
|
118
|
+
|
|
119
|
+
- 页面按 `pages/` 约定式路由组织,动态路由正确配置
|
|
120
|
+
- 渲染模式(SSR/SSG/SPA)选择正确,`nuxt.config.ts` 配置清晰
|
|
121
|
+
- 数据获取使用 `useFetch` / `useAsyncData`,自动去重和水合
|
|
122
|
+
- Composables 和组件自动导入正确,服务端/客户端边界清晰
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-performance-optimization
|
|
3
|
+
description: Use when diagnosing or improving frontend performance, Core Web Vitals, bundle size, runtime rendering cost, network waterfalls, memory leaks, long tasks, Lighthouse findings, or performance budgets; Chinese triggers include 性能优化, 页面卡顿, 首屏慢, 包体积, Web Vitals.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 前端性能优化
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
用可度量的方式定位前端性能瓶颈,并把优化建议收敛到用户主路径、构建产物和运行时证据。
|
|
11
|
+
|
|
12
|
+
## Procedure
|
|
13
|
+
|
|
14
|
+
1. 锁定体验目标
|
|
15
|
+
- 明确问题属于首屏加载、交互延迟、滚动卡顿、内存上涨、网络瀑布、包体积,还是视觉稳定性。
|
|
16
|
+
- 记录路由、设备、网络条件、浏览器、复现步骤和当前可用指标。
|
|
17
|
+
- 没有指标时先建立基线,不直接给出“优化一切”的泛化建议。
|
|
18
|
+
|
|
19
|
+
2. 建立度量基线
|
|
20
|
+
- 读取项目脚本、构建配置、依赖和已有性能报告。
|
|
21
|
+
- 对页面体验优先使用 Lighthouse、Performance trace、React Profiler、Vue Devtools、Memory snapshot 或 RUM 数据。
|
|
22
|
+
- 对包体优先看构建产物、source map、依赖重复、首屏 chunk 和动态 import 边界。
|
|
23
|
+
- 对运行时卡顿优先看长任务、重复渲染、昂贵计算、同步循环、布局抖动和大列表。
|
|
24
|
+
|
|
25
|
+
3. 分层定位
|
|
26
|
+
- 加载层:关键 CSS、字体、图片、脚本阻塞、预加载和缓存。
|
|
27
|
+
- 渲染层:不稳定 key、过宽 Context、无意义 effect、重复计算、组件树过大。
|
|
28
|
+
- 数据层:串行请求、重复请求、过大 payload、缺少分页或缓存策略。
|
|
29
|
+
- 主线程:JSON/CSV 解析、图片处理、复杂排序过滤、同步压缩和大对象深拷贝。
|
|
30
|
+
- 资源层:事件监听、定时器、订阅、WebGL/Canvas 资源和对象 URL 未释放。
|
|
31
|
+
|
|
32
|
+
4. 形成优化方案
|
|
33
|
+
- 每个建议必须绑定位置、影响、改法和验证方式。
|
|
34
|
+
- 优先处理高频主路径和 P95 体验;低频后台任务不抢占首屏预算。
|
|
35
|
+
- 先做低风险高收益改动,如懒加载、去重、缓存、尺寸预留、虚拟列表、稳定引用和释放资源。
|
|
36
|
+
- 对会牺牲可维护性的技巧,必须说明收益证据和替代方案。
|
|
37
|
+
|
|
38
|
+
5. 验证回归
|
|
39
|
+
- 重新运行受影响构建、测试和性能采集命令。
|
|
40
|
+
- 对比优化前后指标或产物体积。
|
|
41
|
+
- 确认 loading、empty、error、offline、reduced-motion 和移动端状态未被优化破坏。
|
|
42
|
+
|
|
43
|
+
## Budgets
|
|
44
|
+
|
|
45
|
+
| Area | Default Target | Notes |
|
|
46
|
+
| ---- | -------------- | ----- |
|
|
47
|
+
| LCP | 约 2.5s 内 | 以核心页面、目标地区网络和真实设备为准 |
|
|
48
|
+
| CLS | 低于 0.1 | 媒体、广告、异步内容需要预留空间 |
|
|
49
|
+
| INP | 约 200ms 内 | 优先拆分长任务和降低交互路径重渲染 |
|
|
50
|
+
| Initial JS | 遵循项目预算 | 没有预算时先报告当前 gzip / brotli 体积 |
|
|
51
|
+
| Main thread | 避免连续长任务 | 大计算考虑分片、缓存或 Worker |
|
|
52
|
+
|
|
53
|
+
## Checks
|
|
54
|
+
|
|
55
|
+
- 首屏资源是否包含非首屏组件、图表、编辑器、地图或全量图标库。
|
|
56
|
+
- 图片是否有明确尺寸、合适格式、懒加载和首屏优先级。
|
|
57
|
+
- 列表、表格、时间线是否需要虚拟化或分页。
|
|
58
|
+
- 搜索、筛选、排序是否在热路径重复 O(n*m) 扫描。
|
|
59
|
+
- 请求是否可并行、可缓存、可取消、可复用。
|
|
60
|
+
- 监听、订阅、定时器、AbortController、Object URL、Canvas/WebGL 资源是否对称清理。
|
|
61
|
+
|
|
62
|
+
## Constraints
|
|
63
|
+
|
|
64
|
+
- 不做没有目标和证据的过早优化。
|
|
65
|
+
- 不靠关闭功能、删除状态反馈或降低可访问性来换性能分数。
|
|
66
|
+
- 不为一次 Lighthouse 分数牺牲真实用户主路径。
|
|
67
|
+
- 不引入大型新依赖解决小问题;先利用项目已有工具和浏览器能力。
|
|
68
|
+
- 不把后端、网络和浏览器侧问题混为一谈;前端能验证的部分要单独列证据。
|
|
69
|
+
|
|
70
|
+
## Expected Output
|
|
71
|
+
|
|
72
|
+
输出性能分析报告,包含基线、指标或观察证据、瓶颈位置、优先级、改法、验证命令和剩余风险。报告保存为 `reports/performance-review-YYYY-MM-DD-HHmmss.md`。
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-pwa-implementation
|
|
3
|
+
description: Use when adding or reviewing Progressive Web App capabilities such as installability, manifest metadata, Service Worker registration, Workbox caching, offline fallback, app update prompts, maskable icons, or iOS PWA compatibility. Do not use for general API caching or non-installable performance tuning; Chinese triggers include PWA, 离线, Service Worker.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# PWA 实现
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
让 Web 应用具备可安装、离线兜底和可控更新能力。
|
|
11
|
+
|
|
12
|
+
## Procedure
|
|
13
|
+
|
|
14
|
+
1. 确认 PWA 是否值得做:面向移动端/桌面安装、弱网离线、重复访问场景时优先;纯内部后台、强实时流媒体或只需要普通缓存时不要强行 PWA。
|
|
15
|
+
2. 先补齐 manifest、图标、主题色和 HTML 引用;图标至少覆盖 192/512,Android 需 maskable,iOS 需 apple touch icon。
|
|
16
|
+
3. 注册 Service Worker,并设计更新提示;不要静默 `skipWaiting()` 后强刷用户页面。
|
|
17
|
+
4. 用 Workbox 或框架插件管理 precache/runtime cache;登录、支付、权限变更等敏感请求必须走网络。
|
|
18
|
+
5. 提供 offline fallback 页面和安装提示 UI,并验证首次加载、离线访问、更新激活、卸载重装。
|
|
19
|
+
|
|
20
|
+
## Detailed References
|
|
21
|
+
|
|
22
|
+
- Load [references/manifest-and-icons.md](references/manifest-and-icons.md) for manifest fields, HTML links, icon requirements, screenshots, and iOS notes.
|
|
23
|
+
- Load [references/service-worker-workbox.md](references/service-worker-workbox.md) for Service Worker registration, Workbox strategies, Vite integration, offline fallback, and update flow.
|
|
24
|
+
|
|
25
|
+
## Constraints
|
|
26
|
+
|
|
27
|
+
- Service Worker 仅在 HTTPS 下工作(localhost 除外)。
|
|
28
|
+
- 缓存策略必须区分页面、静态资源、API 与敏感操作;不要把登录、支付、权限接口缓存起来。
|
|
29
|
+
- Service Worker 更新有生命周期延迟;用户可见刷新提示优先于强制刷新。
|
|
30
|
+
- iOS PWA 能力弱于 Android,安装、推送和生命周期都要单独验证。
|
|
31
|
+
- 缓存有配额和逐出机制,必须设置 max entries / max age。
|
|
32
|
+
|
|
33
|
+
## Expected Output
|
|
34
|
+
|
|
35
|
+
产出可安装的 Web 应用、离线 fallback、可见更新提示和明确缓存策略。验证 Lighthouse PWA、DevTools Application 面板、离线模式、更新发布和移动端安装流程。
|
|
36
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Manifest、图标与安装入口
|
|
2
|
+
|
|
3
|
+
## Manifest 示例
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"name": "我的应用",
|
|
8
|
+
"short_name": "应用",
|
|
9
|
+
"start_url": "/",
|
|
10
|
+
"display": "standalone",
|
|
11
|
+
"background_color": "#ffffff",
|
|
12
|
+
"theme_color": "#0052cc",
|
|
13
|
+
"description": "应用描述",
|
|
14
|
+
"icons": [
|
|
15
|
+
{
|
|
16
|
+
"src": "/icon-192.png",
|
|
17
|
+
"sizes": "192x192",
|
|
18
|
+
"type": "image/png",
|
|
19
|
+
"purpose": "any maskable"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
"src": "/icon-512.png",
|
|
23
|
+
"sizes": "512x512",
|
|
24
|
+
"type": "image/png",
|
|
25
|
+
"purpose": "any maskable"
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"screenshots": [
|
|
29
|
+
{
|
|
30
|
+
"src": "/screenshot-desktop.png",
|
|
31
|
+
"sizes": "1280x720",
|
|
32
|
+
"type": "image/png",
|
|
33
|
+
"form_factor": "wide"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## HTML 引用
|
|
40
|
+
|
|
41
|
+
```html
|
|
42
|
+
<link rel="manifest" href="/manifest.json" />
|
|
43
|
+
<meta name="theme-color" content="#0052cc" />
|
|
44
|
+
<link rel="apple-touch-icon" href="/icon-192.png" />
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 检查要点
|
|
48
|
+
|
|
49
|
+
- `display: "standalone"` 才有接近原生应用的启动体验。
|
|
50
|
+
- `purpose: "any maskable"` 避免 Android 自适应图标被裁剪。
|
|
51
|
+
- `start_url` 应指向登录后或游客可安全进入的入口。
|
|
52
|
+
- `screenshots` 会影响安装对话框质量。
|
|
53
|
+
- iOS 仍依赖 `apple-touch-icon`,安装提示也通常需要用户手动完成。
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Service Worker、Workbox 与更新流
|
|
2
|
+
|
|
3
|
+
## 注册 Service Worker
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
export function registerServiceWorker() {
|
|
7
|
+
if (!("serviceWorker" in navigator)) return;
|
|
8
|
+
|
|
9
|
+
window.addEventListener("load", async () => {
|
|
10
|
+
const registration = await navigator.serviceWorker.register("/sw.js", {
|
|
11
|
+
scope: "/",
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
registration.addEventListener("updatefound", () => {
|
|
15
|
+
const nextWorker = registration.installing;
|
|
16
|
+
nextWorker?.addEventListener("statechange", () => {
|
|
17
|
+
if (nextWorker.state === "installed" && navigator.serviceWorker.controller) {
|
|
18
|
+
showUpdatePrompt();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## 缓存策略
|
|
27
|
+
|
|
28
|
+
| 策略 | 适用 | 注意 |
|
|
29
|
+
| --- | --- | --- |
|
|
30
|
+
| `CacheFirst` | 带 hash 的图片、字体、CSS/JS | 必须设置过期策略 |
|
|
31
|
+
| `NetworkFirst` | 页面导航、低风险 GET API | 网络失败才降级缓存 |
|
|
32
|
+
| `StaleWhileRevalidate` | 字体、头像、低风险静态数据 | 用户会先看到旧数据 |
|
|
33
|
+
| `NetworkOnly` | 登录、支付、权限、写操作 | 不进入 SW 缓存 |
|
|
34
|
+
|
|
35
|
+
## Vite 集成
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
import { VitePWA } from "vite-plugin-pwa";
|
|
39
|
+
import { defineConfig } from "vite";
|
|
40
|
+
|
|
41
|
+
export default defineConfig({
|
|
42
|
+
plugins: [
|
|
43
|
+
VitePWA({
|
|
44
|
+
registerType: "prompt",
|
|
45
|
+
injectRegister: "auto",
|
|
46
|
+
workbox: {
|
|
47
|
+
globPatterns: ["**/*.{js,css,html,ico,png,svg,woff2}"],
|
|
48
|
+
runtimeCaching: [
|
|
49
|
+
{
|
|
50
|
+
urlPattern: /\.(?:png|jpg|jpeg|svg|gif|webp)$/,
|
|
51
|
+
handler: "CacheFirst",
|
|
52
|
+
options: {
|
|
53
|
+
cacheName: "images",
|
|
54
|
+
expiration: { maxEntries: 100, maxAgeSeconds: 30 * 24 * 60 * 60 },
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
}),
|
|
60
|
+
],
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## 离线与更新
|
|
65
|
+
|
|
66
|
+
- 为未缓存页面准备 `/offline.html`,不要让用户只看到浏览器错误页。
|
|
67
|
+
- 更新提示应说明“新版本已可用”,由用户确认刷新。
|
|
68
|
+
- 调试时使用 DevTools Application 面板,必要时清理旧 Service Worker 和 Cache Storage。
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: fec-react-project-standard
|
|
3
|
+
description: Use when designing or reviewing React + TypeScript project structure, feature/module boundaries, component architecture, hooks organization, routing composition, state/API/error/styling defaults, or repository-wide React conventions. Prefer narrower skills for forms, data fetching, tests, accessibility, virtualization, animation, or security deep dives; Chinese triggers include React 项目规范, React 组件架构.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# React 项目规范
|
|
7
|
+
|
|
8
|
+
适用于 React + TypeScript 仓库中的中大型模块建设、页面重构和工程结构设计。
|
|
9
|
+
|
|
10
|
+
## Purpose
|
|
11
|
+
|
|
12
|
+
为 React + TypeScript 项目提供工程结构、模块边界和默认实现约定,确保架构清晰、代码可维护。
|
|
13
|
+
|
|
14
|
+
## Procedure
|
|
15
|
+
|
|
16
|
+
本 skill 主要解决 React 工程任务“如何设计和落地”的问题,不重复声明基础编码底线。处理 React 工程化任务时,按以下顺序执行:
|
|
17
|
+
|
|
18
|
+
1. 识别仓库已有约定
|
|
19
|
+
- 目录组织方式
|
|
20
|
+
- 样式体系
|
|
21
|
+
- 状态管理方案
|
|
22
|
+
- 请求封装方式
|
|
23
|
+
- 测试框架
|
|
24
|
+
- UI 组件库 / 设计系统
|
|
25
|
+
|
|
26
|
+
2. 判断目标属于哪一层
|
|
27
|
+
- 路由页面
|
|
28
|
+
- 页面私有组件
|
|
29
|
+
- feature 业务模块
|
|
30
|
+
- 全局通用组件
|
|
31
|
+
- hooks / services / stores / utils
|
|
32
|
+
|
|
33
|
+
3. 设计边界后再落代码
|
|
34
|
+
- 哪些逻辑属于页面编排
|
|
35
|
+
- 哪些逻辑属于 feature
|
|
36
|
+
- 哪些逻辑应下沉为通用能力
|
|
37
|
+
- 哪些状态应本地管理,哪些应交给 store / query / URL
|
|
38
|
+
- 状态归属复杂时使用状态管理流程先做状态清单
|
|
39
|
+
- DTO、公共 props 或泛型组件复杂时使用 TypeScript 类型安全流程先收敛类型契约
|
|
40
|
+
|
|
41
|
+
4. 输出时补齐关键质量项
|
|
42
|
+
- loading / error / empty / data 状态
|
|
43
|
+
- 错误处理与重试
|
|
44
|
+
- 类型约束
|
|
45
|
+
- 关键测试入口
|
|
46
|
+
- 必要的专项 skill 分流
|
|
47
|
+
- 依赖是否已存在于 `package.json`,缺失时先给安装命令再使用
|
|
48
|
+
- 重型 UI 能力(动效、图表、3D、编辑器、地图)是否隔离为 leaf component 并按需加载
|
|
49
|
+
- 图片、视频、字体等资源是否本地化、可缓存,并避免占位 URL 进入交付
|
|
50
|
+
- 页面级 Error Boundary、模块级 fallback、API 错误映射和用户可恢复动作是否一致
|
|
51
|
+
- Tailwind token/variant 或响应式布局需求是否应分流到对应专项 skill
|
|
52
|
+
|
|
53
|
+
## Detailed References
|
|
54
|
+
|
|
55
|
+
需要具体 React 项目结构、组件模式、Hooks、路由、状态归属、API 层形状、错误处理、样式默认值、TypeScript 约定或审查清单时,加载 [references/react-project-details.md](references/react-project-details.md)。
|
|
56
|
+
|
|
57
|
+
## Constraints
|
|
58
|
+
|
|
59
|
+
- 默认遵守仓库现有全局规则和 React rule
|
|
60
|
+
- 若仓库已有明确目录结构、样式体系、状态管理或请求封装,优先沿用仓库约定
|
|
61
|
+
- 组件文件规模宜约 **300 行**内;逾 **500 行**或复杂度过高须拆分子组件、Hooks、utils、类型
|
|
62
|
+
- 禁止新增类组件(Error Boundary 用 `react-error-boundary` 等库)
|
|
63
|
+
- 禁止绕过模块出口,从 feature 深层路径导入
|
|
64
|
+
- 不要用 `useEffect + setState` 模拟本可直接计算的派生值
|
|
65
|
+
- 避免 prop drilling 过深却不考虑组合或局部封装
|
|
66
|
+
- 不在通用页面组件里同步引入 GSAP、Three.js、Lottie、富文本编辑器或地图 SDK;需要时用动态导入、路由级分包或叶子组件隔离。
|
|
67
|
+
- 不在 React 组件中散落裸 `fetch`、API URL、token refresh 或上传流程;跨边界请求应收敛到 API 集成层。
|
|
68
|
+
- 不用 Error Boundary 处理普通 API 失败;请求错误应优先落到 loading/error/empty/data 状态和可恢复操作。
|
|
69
|
+
|
|
70
|
+
## Expected Output
|
|
71
|
+
|
|
72
|
+
- 组件边界清晰,pages/features/components 分层明确
|
|
73
|
+
- Props 类型完整且明确,无 `any` 滥用
|
|
74
|
+
- 可复用逻辑已提取为 hooks,loading/error/empty/data 状态齐全
|
|
75
|
+
- API 层具备类型约束和统一错误处理,状态管理符合就近原则
|
|
76
|
+
- URL 状态、服务端状态、表单状态和全局客户端状态边界明确
|
|
77
|
+
- 关键行为有测试覆盖,关键模块已用 `react-error-boundary` 包裹
|
|
78
|
+
- 超长列表已评估虚拟化,弹窗/复合组件具备键盘与焦点支持
|
|
79
|
+
- 先尊重仓库现状,再给推荐结构
|
|
80
|
+
- 给出必要的文件划分建议
|
|
81
|
+
- 必要时说明为什么这样分层
|
|
82
|
+
- 对新增模块,优先输出最小可落地结构,而不是一次性过度设计
|
|
83
|
+
- 对重构任务,优先保证可迁移性和风险可控
|