import type { NextConfig } from "next"; /** 由 scripts/build-safe.cjs 设置;在 VPS 上也可手动 export 后执行 pnpm build */ const lowMemBuild = process.env.NEXT_BUILD_LOW_MEM === "1"; const nextConfig: NextConfig = { experimental: { serverActions: { bodySizeLimit: "25mb" }, ...(lowMemBuild ? { // 限制并行与预渲染并发,降低峰值内存(Next 16 默认 Turbopack 构建) cpus: 1, turbopackMemoryLimit: 1536 * 1024 * 1024, staticGenerationMaxConcurrency: 1, webpackMemoryOptimizations: true, parallelServerCompiles: false, parallelServerBuildTraces: false, } : {}), }, async headers() { const noCacheHeaders = [ { key: "Cache-Control", value: "no-store, no-cache, must-revalidate, proxy-revalidate", }, { key: "Pragma", value: "no-cache" }, { key: "Expires", value: "0" }, ]; return [ { source: "/", headers: noCacheHeaders }, { // 排除 /_next/ 静态资源(含 hash 可长期缓存),其余页面禁用缓存 source: "/:path((?!_next).*)", headers: noCacheHeaders, }, ]; }, }; export default nextConfig;