初始化
- 作者仓库星标 38
- 许可证 MIT
- 作者仓库 builder-skills
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 94 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @kazdenc · MIT
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- Linux
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 命令执行
- 读取环境变量
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
第6步:环境设置
使用模板创建`.env.local`:使用相同的键但没有值创建`.env.example`。确保 `.env.local` 位于 `.gitignore` 中(create-next-app 默认执行此操作)。
第 7 步:起始根布局
将 `src/app/layout.tsx` 替换为:
第 8 步:添加实用程序助手
创建`src/lib/utils.ts`:安装依赖项:
# Next.js Project Scaffold
Create a production-ready Next.js project with App Router, TypeScript, and Tailwind CSS. If the user provides a `target`, use it as the project name. Otherwise, ask.
## Step 1: Run create-next-app
Execute this command, replacing `<project-name>` with the target:
```bash
npx create-next-app@latest <project-name> \
--typescript \
--tailwind \
--eslint \
--app \
--src-dir \
--import-alias "@/*" \
--use-pnpm
```
If the user prefers npm or yarn, swap `--use-pnpm` accordingly. Default to pnpm.
## Step 2: Set Up Directory Structure
Create these directories inside `src/`:
```
src/
app/ # Routes and layouts (created by create-next-app)
(auth)/ # Auth route group
(dashboard)/ # Main app route group
api/ # API routes
layout.tsx # Root layout
page.tsx # Landing page
components/
ui/ # Reusable primitives (Button, Input, Card)
forms/ # Form components
layout/ # Header, Footer, Sidebar, Nav
lib/
utils.ts # Shared utility functions
constants.ts # App-wide constants
types/
index.ts # Shared TypeScript types
hooks/ # Custom React hooks
styles/
globals.css # Already created by create-next-app
```
```bash
mkdir -p src/{components/{ui,forms,layout},lib,types,hooks,app/{\\(auth\\),\\(dashboard\\),api}}
```
## Step 3: Configure TypeScript
Verify `tsconfig.json` has these settings. Patch if missing:
```json
{
"compilerOptions": {
"strict": true,
"noUncheckedIndexedAccess": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@/*": ["./src/*"]
}
}
}
```
| Setting | Why |
|---------|-----|
| `strict: true` | Catches type errors early. Non-negotiable. |
| `noUncheckedIndexedAccess` | Forces handling of `undefined` from array/object access |
| `forceConsistentCasingInFileNames` | Prevents deploy failures on case-sensitive Linux servers |
## Step 4: Configure ESLint
Extend `.eslintrc.json`:
```json
{
"extends": [
"next/core-web-vitals",
"next/typescript"
],
"rules": {
"prefer-const": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }]
}
}
```
## Step 5: Add Prettier
```bash
pnpm add -D prettier prettier-plugin-tailwindcss
```
Create `.prettierrc`:
```json
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"plugins": ["prettier-plugin-tailwindcss"]
}
```
Create `.prettierignore`:
```
node_modules
.next
dist
pnpm-lock.yaml
```
## Step 6: Environment Setup
Create `.env.local` with a template:
```bash
# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
# Database (fill in after setting up Supabase or other DB)
# DATABASE_URL=
# Auth (fill in after setting up auth provider)
# NEXTAUTH_SECRET=
# NEXTAUTH_URL=http://localhost:3000
```
Create `.env.example` with the same keys but no values. Ensure `.env.local` is in `.gitignore` (create-next-app does this by default).
## Step 7: Starter Root Layout
Replace `src/app/layout.tsx` with:
```tsx
import type { Metadata } from 'next'
import { Inter } from 'next/font/google'
import '@/styles/globals.css'
const inter = Inter({ subsets: ['latin'] })
export const metadata: Metadata = {
title: 'App Name',
description: 'App description',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<html lang="en">
<body className={inter.className}>{children}</body>
</html>
)
}
```
## Step 8: Add Utility Helpers
Create `src/lib/utils.ts`:
```ts
import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
```
Install the dependencies:
```bash
pnpm add clsx tailwind-merge
```
## Step 9: Verify
Run these checks before handing off:
```bash
pnpm build # Must compile without errors
pnpm lint # Must pass with zero warnings
```
## Post-Scaffold Checklist
| Task | Status |
|------|--------|
| `create-next-app` ran with correct flags | |
| Directory structure created | |
| TypeScript strict mode enabled | |
| ESLint configured | |
| Prettier + Tailwind plugin installed | |
| `.env.local` template created | |
| `.env.example` created (no secrets) | |
| Root layout uses Inter font + metadata | |
| `cn()` utility installed | |
| `pnpm build` passes | |
| `pnpm lint` passes | |
章节与文件索引
按说明文件中的顺序排列。
第 1 步:运行 create-next-app
第2步:设置目录结构
第 3 步:配置 TypeScript
第 4 步:配置 ESLint
第 5 步:添加更漂亮的内容
文件/命令 -> target · <project-name> · --use-pnpm · src/ · tsconfig.json · strict: true · noUncheckedIndexedAccess · undefined
内容校验值 -> 4f61f964674b
当前原文的自动摘译,尚未人工审校。
第 1 步:运行 create-next-app
执行此命令,将
<project-name>替换为目标:如果用户更喜欢npm或yarn,请相应地交换--use-pnpm。默认为 pnpm。第2步:设置目录结构
在
src/中创建这些目录:第 3 步:配置 TypeScript
验证
tsconfig.json具有这些设置。如果缺少补丁:设置·为什么strict: true·尽早捕获类型错误。没有商量的余地。noUncheckedIndexedAccess· 从数组/对象访问中强制处理undefinedforceConsistentCasingInFileNames· 防止在区分大小写的 Linux 服务器上部署失败第 4 步:配置 ESLint
扩展
.eslintrc.json:第 5 步:添加更漂亮的内容
创建
.prettierrc: 创建.prettierignore: