const crypto = require('crypto') /** @type {import('next').NextConfig} */ const nextConfig = { reactStrictMode: true, swcMinify: true, output: 'standalone', env: { NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:12011', }, webpack: (config, { dev, isServer }) => { // 在生產環境中禁用 HMR 相關功能 if (!dev && !isServer) { config.optimization = { ...config.optimization, splitChunks: { chunks: 'all', cacheGroups: { default: false, vendors: false, framework: { chunks: 'all', name: 'framework', test: /(? 160000 && /node_modules[/\\]/.test(module.identifier()) }, name(module) { const hash = crypto.createHash('sha1') hash.update(module.identifier()) return hash.digest('hex').substring(0, 8) }, priority: 30, minChunks: 1, reuseExistingChunk: true, }, commons: { name: 'commons', minChunks: 2, priority: 20, }, }, }, } } return config }, async rewrites() { return [ { source: '/api/:path*', destination: `${process.env.NEXT_PUBLIC_API_URL || 'http://localhost:12011'}/api/:path*`, }, ] }, images: { domains: ['localhost'], }, } module.exports = nextConfig