11const isStaticExport = process . env . NODE_ENV === 'production' || process . env . NEXT_PRIVATE_STATIC_EXPORT === 'true' ;
22const repoName = process . env . NEXT_PUBLIC_GITHUB_REPO_NAME || 'OxygenBlogPlatform' ;
33
4- // 后台管理系统相关的路由(在静态导出时排除)
5- const adminRoutes = [
6- '/admin' ,
7- '/api/admin' ,
8- ] ;
9-
104const nextConfig = {
115 reactStrictMode : true ,
12-
6+
137 turbopack : { } ,
14-
8+
159 compiler : {
1610 reactRemoveProperties : isStaticExport ,
1711 removeConsole : isStaticExport ? { exclude : [ 'error' ] } : false ,
1812 emotion : true ,
1913 } ,
20-
14+
2115 // 性能优化配置
2216 // 启用HTTP压缩
2317 compress : true ,
@@ -35,24 +29,19 @@ const nextConfig = {
3529 // 静态导出时必须禁用图片优化
3630 unoptimized : isStaticExport ,
3731 } ,
38-
32+
3933 // 静态导出配置
4034 ...( isStaticExport && {
4135 // 静态导出配置
4236 output : "export" ,
4337 distDir : 'out' ,
4438 trailingSlash : true ,
45-
46- // 排除后台管理系统相关路由(这些需要服务器端支持)
47- excludeFiles : ( filename : string ) => {
48- return adminRoutes . some ( route => filename . includes ( route ) ) ;
49- } ,
50-
39+
5140 // 使用环境变量设置basePath和assetPrefix,确保GitHub Pages部署正常
5241 // 对于静态导出模式,优先使用空字符串作为基础路径
5342 basePath : ( process . env . CUSTOM_DOMAIN === 'true' || process . env . NEXT_PUBLIC_SITE_URL === 'https://blog.xinchengp.cn' ) ? '' : ( process . env . NEXT_PUBLIC_BASE_PATH || '' ) ,
5443 assetPrefix : ( process . env . CUSTOM_DOMAIN === 'true' || process . env . NEXT_PUBLIC_SITE_URL === 'https://blog.xinchengp.cn' ) ? '' : ( process . env . NEXT_PUBLIC_BASE_PATH || '' ) ,
55-
44+
5645 // 图片配置(仅在静态导出模式下需要)
5746 images : {
5847 // 静态导出时必须禁用图片优化
@@ -64,7 +53,7 @@ const nextConfig = {
6453 } ,
6554 ] ,
6655 } ,
67-
56+
6857 // 确保环境变量正确注入
6958 env : {
7059 NEXT_PUBLIC_BASE_PATH : process . env . NEXT_PUBLIC_BASE_PATH || '' ,
@@ -73,7 +62,7 @@ const nextConfig = {
7362 CUSTOM_DOMAIN : process . env . CUSTOM_DOMAIN || 'false' ,
7463 } ,
7564 } ) ,
76-
65+
7766 // 开发环境配置(非静态导出)
7867 ...( ! isStaticExport && {
7968 // 开发环境禁用静态导出
@@ -82,28 +71,28 @@ const nextConfig = {
8271 basePath : '' ,
8372 assetPrefix : '' ,
8473 } ) ,
85-
74+
8675 // 环境变量配置
8776 env : {
8877 // 静态导出标识
8978 IS_STATIC_EXPORT : isStaticExport . toString ( ) ,
9079 // GitHub仓库名
9180 NEXT_PUBLIC_GITHUB_REPO_NAME : repoName ,
9281 } ,
93-
82+
9483 // 确保正确处理Unicode字符
9584 pageExtensions : [ "tsx" , "ts" , "jsx" , "js" ] ,
96-
85+
9786 // 缓存配置
9887 generateBuildId : async ( ) => {
9988 return new Date ( ) . getTime ( ) . toString ( ) ;
10089 } ,
101-
90+
10291 poweredByHeader : false ,
103-
92+
10493 // 生成源映射(仅在开发环境)
10594 productionBrowserSourceMaps : ! isStaticExport ,
106-
95+
10796 // 优化HTTP头 (仅在非静态导出模式下启用)
10897 ...( isStaticExport ? { } : {
10998 headers : async ( ) => {
@@ -159,4 +148,4 @@ const nextConfig = {
159148 } ) ,
160149} ;
161150
162- export default nextConfig ;
151+ export default nextConfig ;
0 commit comments