.cursor/rules/project.mdc
--- description: Next.js app, routes, React components, server actions, and frontend checks globs: ["app/**/*","components/**/*","lib/**/*","pages/**/*","next.config.*","package.json"] alwaysApply: true --- # Cursor Project Rules File: .cursor/rules/nextjs.mdc ## Project Context - Project type: Next.js - Tech stack: Next.js, TypeScript, React, CSS modules - Coding style: Prefer small components, explicit types, accessible UI, and existing project patterns. - AI tool target: Cursor Rules 生成器:.cursor/rules 与 .mdc 文件 ## Project Commands - Package manager: npm - Test: `npm test` - Build: `npm run build` - Lint: `npm run lint` ## Stack-Specific Rules - Use existing app router, component, and data-fetching patterns before adding new abstractions. - Keep server and client component boundaries explicit. - Preserve accessibility, responsive layout, metadata, and route-level SEO behavior. - Run lint, tests, and build checks before handoff. ## Avoid - Do not introduce duplicate fetch wrappers or UI primitives when local helpers exist. - Do not move client-only code into server components. - Do not hide build or hydration failures. ## How Cursor Should Work - Inspect existing patterns before adding new abstractions. - Keep edits scoped to the requested behavior. - Prefer typed, accessible, maintainable code. - Run targeted checks before final handoff when possible. - If a command fails, report the exact failure and the likely next step. - Link related rules from the Cursor Rules Directory when this file grows too broad. ## Extra Instructions Before handoff, summarize changed files and mention any checks that could not be run.
使用 Cursor Rules 生成器,为 Next.js、Python、Laravel、Chrome extension 和 SaaS 项目创建 stack-specific .cursor/rules .mdc 文件。
选择项目栈模板
从最接近仓库的项目栈开始。生成器会填入 globs、命令、审查防护和 stack-specific 注意事项。
什么是好的 Cursor Rule
好的 Cursor Rules 具体且有范围。它会说明规则适用哪些文件、应该复用哪些模式、需要哪些验证命令,以及 Cursor 应避免哪些错误。
示例与目录
当一个项目级规则变得过宽时,按框架、package、测试或产品区域拆分 .mdc 文件。
如何维护 Cursor Rules
当代码结构变化,或开发者反复纠正同一种 AI 行为时,就应该审查规则。只有当一个项目级文件过宽时,才按 package、框架或文件类型拆分。
常见问题
Cursor Rules 放在哪里?
项目规则通常放在 .cursor/rules 下,常见起点是 project.mdc,也可以拆成 nextjs.mdc、tests.mdc 等。
规则能只匹配部分文件吗?
可以。用 globs 把规则限制到 package、框架、文件类型、测试或产品区域。
包含哪些模板?
生成器包含 Next.js、Python、Laravel、Chrome extension 和 SaaS 预设,也保留通用 fallback。
一个仓库应该有多个 .mdc 文件吗?
当不同区域规则明显不同时可以拆分。先保留项目基线,再逐步拆出专项规则。