| 1 | import path from 'node:path' |
| 2 | import { fileURLToPath } from 'node:url' |
| 3 | |
| 4 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) |
| 5 | const publicAssetsVersion = '20260517' |
| 6 | const publicAssetsCacheControl = 'public, max-age=0, must-revalidate' |
| 7 | |
| 8 | /** @type {import('next').NextConfig} */ |
| 9 | const nextConfig = { |
| 10 | images: { |
| 11 | unoptimized: true, |
| 12 | }, |
| 13 | webpack(config) { |
| 14 | config.module.rules.push({ |
| 15 | test: /\.svg$/, |
| 16 | use: ['@svgr/webpack'], |
| 17 | exclude: path.resolve(__dirname, 'src/assets/svgs/plat'), |
| 18 | }) |
| 19 | |
| 20 | config.module.rules.push({ |
| 21 | test: /\.svg$/, |
| 22 | include: path.resolve(__dirname, 'src/assets/svgs/plat'), |
| 23 | type: 'asset/resource', |
| 24 | }) |
| 25 | |
| 26 | return config |
| 27 | }, |
| 28 | reactStrictMode: false, |
| 29 | experimental: { |
| 30 | forceSwcTransforms: true, |
| 31 | outputFileTracingRoot: undefined, |
| 32 | }, |
| 33 | output: 'standalone', // Temporarily disabled to avoid symlink issues on Windows |
| 34 | productionBrowserSourceMaps: process.env.NEXT_PUBLIC_EVN === 'dev', |
| 35 | rewrites: async () => { |
| 36 | const rewrites = [] |
| 37 | |
| 38 | if (process.env.NEXT_PUBLIC_OSS_URL_PROXY && process.env.NEXT_PUBLIC_OSS_URL) { |
| 39 | rewrites.push({ |
| 40 | source: `${process.env.NEXT_PUBLIC_OSS_URL_PROXY}:path*`, |
| 41 | destination: `${process.env.NEXT_PUBLIC_OSS_URL}/:path*`, |
| 42 | }) |
| 43 | } |
| 44 | |
| 45 | // 存在 NEXT_PUBLIC_PROXY_URL 则代理,本地直连 用 |
| 46 | // 如:NEXT_PUBLIC_PROXY_URL = http://localhost:8080 |
| 47 | if (process.env.NEXT_PUBLIC_PROXY_URL) { |
| 48 | rewrites.push({ |
| 49 | source: `/api/:path*`, |
| 50 | destination: `${process.env.NEXT_PUBLIC_PROXY_URL}/api/:path*`, |
| 51 | }) |
| 52 | rewrites.push({ |
| 53 | source: `/health`, |
| 54 | destination: `${process.env.NEXT_PUBLIC_PROXY_URL}/health`, |
| 55 | }) |
| 56 | } |
| 57 | return rewrites |
| 58 | }, |
| 59 | redirects: async () => { |
| 60 | return [ |
| 61 | { |
| 62 | source: '/assets/:path*', |
| 63 | missing: [{ type: 'query', key: 'v' }], |
| 64 | destination: `/assets/:path*?v=${publicAssetsVersion}`, |
| 65 | permanent: false, |
| 66 | }, |
| 67 | ] |
| 68 | }, |
| 69 | } |
| 70 | |
| 71 | const CorsHeaders = [ |
| 72 | { key: 'Access-Control-Allow-Credentials', value: 'true' }, |
| 73 | { key: 'Access-Control-Allow-Origin', value: '*' }, |
| 74 | { |
| 75 | key: 'Access-Control-Allow-Methods', |
| 76 | value: '*', |
| 77 | }, |
| 78 | { |
| 79 | key: 'Access-Control-Allow-Headers', |
| 80 | value: '*', |
| 81 | }, |
| 82 | { |
| 83 | key: 'Access-Control-Max-Age', |
| 84 | value: '86400', |
| 85 | }, |
| 86 | ] |
| 87 | |
| 88 | nextConfig.headers = async () => { |
| 89 | return [ |
| 90 | { |
| 91 | source: '/api/:path*', |
| 92 | headers: CorsHeaders, |
| 93 | }, |
| 94 | { |
| 95 | source: '/assets/:path*', |
| 96 | headers: [ |
| 97 | { |
| 98 | key: 'Cache-Control', |
| 99 | value: publicAssetsCacheControl, |
| 100 | }, |
| 101 | ], |
| 102 | }, |
| 103 | { |
| 104 | // 为所有页面添加 SEO 相关的 headers |
| 105 | source: '/:path*', |
| 106 | headers: [ |
| 107 | { |
| 108 | key: 'Content-Signal', |
| 109 | value: 'search=yes, ai-train=yes', // 注意:逗号后面有空格,这是正确的语法 |
| 110 | }, |
| 111 | ], |
| 112 | }, |
| 113 | ] |
| 114 | } |
| 115 | |
| 116 | export default nextConfig |
| 117 |