Loading...
Loading...
Compare original and translation side by side
project/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── layout.tsx
│ │ ├── page.tsx
│ │ └── globals.css
│ ├── components/ # Shared components
│ └── lib/ # Utility functions
├── public/ # Static assets
├── next.config.js # Next.js configuration
├── tsconfig.json # TypeScript config
└── package.jsonproject/
├── src/
│ ├── app/ # Next.js App Router
│ │ ├── layout.tsx
│ │ ├── page.tsx
│ │ └── globals.css
│ ├── components/ # 通用组件
│ └── lib/ # 工具函数
├── public/ # 静态资源
├── next.config.js # Next.js 配置文件
├── tsconfig.json # TypeScript 配置文件
└── package.jsonundefinedundefinedundefinedundefined// next.config.js
module.exports = {
experimental: {
turbo: {
// Turbopack-specific configuration
}
}
};// next.config.js
module.exports = {
experimental: {
turbo: {
// Turbopack专属配置
}
}
};// next.config.js
module.exports = {
turbopack: {
rules: {
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js'
},
'*.mdx': {
loaders: ['@mdx-js/loader']
}
}
}
};// next.config.js
module.exports = {
turbopack: {
rules: {
'*.svg': {
loaders: ['@svgr/webpack'],
as: '*.js'
},
'*.mdx': {
loaders: ['@mdx-js/loader']
}
}
}
};// next.config.js
module.exports = {
turbopack: {
resolveAlias: {
'@components': './src/components',
'@lib': './src/lib',
'@styles': './src/styles'
}
}
};// next.config.js
module.exports = {
turbopack: {
resolveAlias: {
'@components': './src/components',
'@lib': './src/lib',
'@styles': './src/styles'
}
}
};// next.config.js
module.exports = {
turbopack: {
resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json']
}
};// next.config.js
module.exports = {
turbopack: {
resolveExtensions: ['.tsx', '.ts', '.jsx', '.js', '.json']
}
};.module.csscss-loaderpostcss-loaderbabel-loader@babel/preset-env.module.csscss-loaderpostcss-loaderbabel-loader@babel/preset-env{
"compilerOptions": {
"target": "ES2017",
"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,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}{
"compilerOptions": {
"target": "ES2017",
"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,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
}
}{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": ["src/components/*"],
"@lib/*": ["src/lib/*"],
"@styles/*": ["src/styles/*"]
}
}
}{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@components/*": ["src/components/*"],
"@lib/*": ["src/lib/*"],
"@styles/*": ["src/styles/*"]
}
}
}src/
├── components/
│ ├── atoms/ # Basic building blocks
│ │ ├── Button/
│ │ └── Input/
│ ├── molecules/ # Combinations of atoms
│ │ ├── SearchBar/
│ │ └── NavItem/
│ ├── organisms/ # Complex components
│ │ ├── Header/
│ │ └── Footer/
│ └── templates/ # Page layouts
│ └── MainLayout/
├── app/
│ └── page.tsx
└── lib/
└── utils.tssrc/
├── components/
│ ├── atoms/ # 基础构建块
│ │ ├── Button/
│ │ └── Input/
│ ├── molecules/ # 多个原子组合而成的组件
│ │ ├── SearchBar/
│ │ └── NavItem/
│ ├── organisms/ # 复杂组件
│ │ ├── Header/
│ │ └── Footer/
│ └── templates/ # 页面布局
│ └── MainLayout/
├── app/
│ └── page.tsx
└── lib/
└── utils.tsButton/
├── Button.tsx
├── Button.module.css
├── Button.test.tsx
└── index.tsButton/
├── Button.tsx
├── Button.module.css
├── Button.test.tsx
└── index.tsimport dynamic from 'next/dynamic';
const HeavyComponent = dynamic(() => import('@/components/HeavyComponent'), {
loading: () => <p>Loading...</p>,
ssr: false // Disable server-side rendering if needed
});import dynamic from 'next/dynamic';
const HeavyComponent = dynamic(() => import('@/components/HeavyComponent'), {
loading: () => <p>加载中...</p>,
ssr: false // 按需禁用服务端渲染
});app/app/// Split large components
const ChartComponent = dynamic(() => import('./ChartComponent'));
const EditorComponent = dynamic(() => import('./EditorComponent'));// 分割大型组件
const ChartComponent = dynamic(() => import('./ChartComponent'));
const EditorComponent = dynamic(() => import('./EditorComponent'));// Keep modules focused and small
// Changes to one module don't invalidate others
// Good: Separate concerns
export function formatDate(date: Date) { /* ... */ }
export function formatCurrency(amount: number) { /* ... */ }
// Avoid: Large utility files that change frequently// 保持模块功能聚焦、体积小巧
// 单个模块的变更不会导致其他模块缓存失效
// 推荐:职责分离
export function formatDate(date: Date) { /* ... */ }
export function formatCurrency(amount: number) { /* ... */ }
// 不推荐:频繁变更的大型工具文件// Prefer specific imports
import { Button } from '@/components/Button';
// Avoid importing entire libraries
// Bad: import _ from 'lodash';
// Good: import debounce from 'lodash/debounce';// 优先使用特定导入
import { Button } from '@/components/Button';
// 避免导入整个库
// 不推荐: import _ from 'lodash';
// 推荐: import debounce from 'lodash/debounce';// Use const assertions for better tree-shaking
const ROUTES = {
home: '/',
about: '/about',
contact: '/contact'
} as const;// 使用const断言获得更好的tree-shaking效果
const ROUTES = {
home: '/',
about: '/about',
contact: '/contact'
} as const;import styles from './Component.module.css';
function Component() {
return <div className={styles.container}>Content</div>;
}import styles from './Component.module.css';
function Component() {
return <div className={styles.container}>内容</div>;
}// app/layout.tsx
import './globals.css';// app/layout.tsx
import './globals.css';// tailwind.config.js
module.exports = {
content: [
'./src/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}'
]
};// tailwind.config.js
module.exports = {
content: [
'./src/**/*.{js,ts,jsx,tsx,mdx}',
'./app/**/*.{js,ts,jsx,tsx,mdx}'
]
};undefinedundefined
```typescript
// Client-side (must have NEXT_PUBLIC_ prefix)
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
// Server-side only
const dbUrl = process.env.DATABASE_URL;
```typescript
// 客户端使用(必须带NEXT_PUBLIC_前缀)
const apiUrl = process.env.NEXT_PUBLIC_API_URL;
// 仅服务端使用
const dbUrl = process.env.DATABASE_URL;src/
├── components/
│ └── Button/
│ ├── Button.tsx
│ └── Button.test.tsx # Co-located test
└── __tests__/ # Integration tests
└── pages/
└── home.test.tsxsrc/
├── components/
│ └── Button/
│ ├── Button.tsx
│ └── Button.test.tsx # 与源码同位置的测试文件
└── __tests__/ # 集成测试
└── pages/
└── home.test.tsx// Ensure correct tsconfig.json paths
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"] // Must match actual structure
}
}
}// 确保tsconfig.json路径配置正确
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"] // 必须与实际目录结构匹配
}
}
}undefinedundefinedundefinedundefinedNEXT_DEBUG_TURBOPACK=1 next dev --turboNEXT_DEBUG_TURBOPACK=1 next dev --turboundefinedundefinedundefinedundefinedtsc --noEmittsc --noEmit