# 检查是否已安装Node.js
node -v
npm -v
# 如果未安装,访问 https://nodejs.org 下载安装包
# 建议安装LTS版本(当前为18.x或20.x)
# 设置淘宝镜像
npm config set registry https://registry.npmmirror.com
# 或安装cnpm
npm install -g cnpm --registry=https://registry.npmmirror.com
npx create-next-app@latest my-next-app
# 在创建过程中,你会看到以下选项:
√ Would you like to use TypeScript? ... yes # 使用TypeScript
√ Would you like to use ESLint? ... yes # 使用ESLint
√ Would you like to use Tailwind CSS? ... yes # 使用Tailwind CSS
√ Would you like to use `src/` directory? ... yes # 使用src目录
√ Would you like to use App Router? ... yes # 使用App Router
√ Would you like to customize the default import alias (@/*)? ... yes # 自定义导入别名
cd my-next-app
# 安装开发依赖
npm install --save-dev @types/node @types/react @types/react-dom
# 安装项目依赖
npm install @prisma/client zustand @headlessui/react @heroicons/react chart.js react-chartjs-2 date-fns
mkdir -p src/{app,components,lib,hooks,services,styles,types}
src/
├── app/ # Next.js 13+ App Router页面
├── components/ # React组件
├── lib/ # 工具函数和配置
├── hooks/ # 自定义React Hooks
├── services/ # API服务
├── styles/ # 样式文件
└── types/ # TypeScript类型定义
// tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"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"]
}
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
images: {
domains: ['localhost'],
},
experimental: {
serverActions: true,
},
}
module.exports = nextConfig
git init
# .gitignore
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
*.pem
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# local env files
.env*.local
.env
# vercel
.vercel
# typescript
*.tsbuildinfo
next-env.d.ts
// src/app/page.tsx
export default function Home() {
return (
欢迎来到MindAI
智能心理健康服务平台
)
}
// src/app/layout.tsx
import './globals.css'
import type { Metadata } from 'next'
export const metadata: Metadata = {
title: 'MindAI - 智能心理健康服务平台',
description: '基于AI技术的现代化心理健康服务平台',
}
export default function RootLayout({
children,
}: {
children: React.ReactNode
}) {
return (
{children}
)
}
npm run dev
打开浏览器访问 http://localhost:3000 查看结果