模板说明
该模板提供现代 Next.js 全栈应用基础,使用 App Router 和服务端组件,样式由 Tailwind 管理。
包含内容
包含 TypeScript 严格配置、Tailwind 管线、App Router 页面与布局、基础组件、SEO 元数据和脚本。
使用建议
服务端组件负责数据获取,客户端组件只处理交互。Tailwind 配合设计令牌,避免散落颜色值。为图片设置尺寸,减少布局偏移;环境变量区分公开与服务端密钥。
验证方式
运行类型检查、构建和 Lighthouse;检查首页、404、元数据和 sitemap。用慢网络验证流式渲染和加载状态,确认禁用 JavaScript 时内容仍可读取。
交付检查
使用该模板初始化项目后,先运行安装、类型检查、测试与生产构建;再按模板说明逐项核对环境变量、权限边界、错误处理和关闭流程。把实际命令输出保留为交付证据,不要只依据 README 声明。
代码示例
package.json
next.config.ts
tsconfig.json
src/app/layout.tsx
src/app/page.tsx
src/app/globals.css
{
"name": "nextjs-tailwind-starter",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"next": "^15.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"typescript": "^5.6.0",
"@types/node": "^22.0.0",
"@types/react": "^19.0.0",
"@types/react-dom": "^19.0.0",
"tailwindcss": "^4.0.0",
"postcss": "^8.4.0",
"autoprefixer": "^10.4.0"
}
}
import type { NextConfig } from 'next';
const nextConfig: NextConfig = {
reactStrictMode: true,
experimental: {
typedRoutes: true,
},
};
export default nextConfig;
{
"compilerOptions": {
"target": "ES2022",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [{ "name": "next" }],
"paths": { "@/*": ["./src/*"] }
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
import type { Metadata } from 'next';
import './globals.css';
export const metadata: Metadata = {
title: 'Next.js + Tailwind Starter',
description: 'A modern full-stack starter template',
};
export default function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
return (
<html lang="en">
<body className="antialiased">{children}</body>
</html>
);
}
export default function HomePage() {
return (
<main className="flex min-h-screen flex-col items-center justify-center p-8">
<h1 className="text-4xl font-bold tracking-tight">
Next.js + Tailwind Starter
</h1>
<p className="mt-4 text-lg text-gray-600">
Get started by editing src/app/page.tsx
</p>
</main>
);
}
@import "tailwindcss";
:root {
--background: #ffffff;
--foreground: #171717;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #0a0a0a;
--foreground: #ededed;
}
}
body {
background: var(--background);
color: var(--foreground);
}