Files
TODO_list_system/frontend/next.config.js
2025-09-03 17:08:22 +08:00

65 lines
1.8 KiB
JavaScript

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: /(?<!node_modules.*)[\\/]node_modules[\\/](react|react-dom|scheduler|prop-types|use-subscription)[\\/]/,
priority: 40,
enforce: true,
},
lib: {
test(module) {
return module.size() > 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