48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
|
|
import path from 'path';
|
||
|
|
|
||
|
|
const isStaticExport = process.env.BUILD_MODE === 'static';
|
||
|
|
|
||
|
|
/** @type {import('next').NextConfig} */
|
||
|
|
const nextConfig = {
|
||
|
|
// 基础配置
|
||
|
|
reactStrictMode: true,
|
||
|
|
poweredByHeader: false,
|
||
|
|
swcMinify: true,
|
||
|
|
...(isStaticExport && {
|
||
|
|
output: 'export',
|
||
|
|
trailingSlash: true,
|
||
|
|
images: {
|
||
|
|
unoptimized: true,
|
||
|
|
},
|
||
|
|
// 静态导出时排除所有API路由
|
||
|
|
experimental: {
|
||
|
|
outputFileTracingExcludes: {
|
||
|
|
'*': ['./app/api/**/*'],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
// 在静态导出时忽略API路由
|
||
|
|
pageExtensions: ['tsx', 'ts', 'jsx', 'js'],
|
||
|
|
// 确保生成根路径的页面
|
||
|
|
async generateBuildId() {
|
||
|
|
return 'static-build'
|
||
|
|
},
|
||
|
|
// 静态导出配置
|
||
|
|
distDir: 'out',
|
||
|
|
}),
|
||
|
|
...(!isStaticExport && {
|
||
|
|
output: 'standalone',
|
||
|
|
}),
|
||
|
|
env: {
|
||
|
|
NEXT_PUBLIC_SITE_URL: process.env.NEXT_PUBLIC_SITE_URL || 'awslinker.com',
|
||
|
|
BUILD_MODE: process.env.BUILD_MODE || 'server',
|
||
|
|
},
|
||
|
|
// 确保构建时包含 docs 目录
|
||
|
|
experimental: {
|
||
|
|
outputFileTracingIncludes: {
|
||
|
|
'/api/articles/**/*': ['./docs/**/*'],
|
||
|
|
},
|
||
|
|
},
|
||
|
|
};
|
||
|
|
|
||
|
|
export default nextConfig;
|