# PowerShell 静态构建脚本 Write-Host "开始静态构建..." -ForegroundColor Green # 1. 清理之前的构建文件 Write-Host "1. 清理之前的构建文件..." -ForegroundColor Yellow if (Test-Path ".next") { Remove-Item ".next" -Recurse -Force -ErrorAction SilentlyContinue Write-Host " 已清理 .next 目录" -ForegroundColor Gray } if (Test-Path "out") { Remove-Item "out" -Recurse -Force -ErrorAction SilentlyContinue Write-Host " 已清理 out 目录" -ForegroundColor Gray } # 2. 临时移动 API 目录 Write-Host "2. 临时移动 API 目录..." -ForegroundColor Yellow $apiMoved = $false if (Test-Path "app\api") { Move-Item "app\api" "app\api-disabled" -ErrorAction SilentlyContinue if (Test-Path "app\api-disabled") { $apiMoved = $true Write-Host " API 目录已临时移动" -ForegroundColor Gray } else { Write-Host " 警告: 无法移动 API 目录,继续构建..." -ForegroundColor Red } } # 3. 构建静态文件 Write-Host "3. 构建静态文件..." -ForegroundColor Yellow & npm run build:static $buildResult = $LASTEXITCODE if ($buildResult -eq 0) { Write-Host " 构建成功完成" -ForegroundColor Green } else { Write-Host " 构建失败,错误代码: $buildResult" -ForegroundColor Red } # 4. 恢复 API 目录 Write-Host "4. 恢复 API 目录..." -ForegroundColor Yellow if ($apiMoved -and (Test-Path "app\api-disabled")) { Move-Item "app\api-disabled" "app\api" -ErrorAction SilentlyContinue if (Test-Path "app\api") { Write-Host " API 目录已恢复" -ForegroundColor Gray } else { Write-Host " 警告: 无法恢复 API 目录,请手动将 app\api-disabled 移动为 app\api" -ForegroundColor Red } } # 5. 显示结果 Write-Host "" if ($buildResult -eq 0) { Write-Host "✅ 静态构建完成!" -ForegroundColor Green Write-Host "📁 静态文件位置: out/ 目录" -ForegroundColor Cyan Write-Host "🚀 可以将 out/ 目录上传到服务器" -ForegroundColor Cyan Write-Host "" Write-Host "预览命令: npm run preview" -ForegroundColor Yellow } else { Write-Host "❌ 构建失败!" -ForegroundColor Red Write-Host "错误代码: $buildResult" -ForegroundColor Red } Write-Host ""