furniture-3d-system-Wu/next.config.js
WuYongJie c98c0519c8 完善用户界面和3D模型展示功能
✨ 新功能:
- 现代化主页设计,包含实时系统统计
- 完整的产品管理页面,显示产品列表和统计信息
- 改进的分享页面界面,支持全屏模式和更好的用户体验
- 增强的3D模型查看器,包含加载状态和错误处理
- 操作提示和交互指导

🎨 界面改进:
- 渐变背景和现代化卡片设计
- 响应式布局和移动端适配
- 统一的颜色主题和视觉风格
- 更好的按钮和交互效果

🔧 技术优化:
- 修复Next.js 16配置问题
- 优化Turbopack配置
- 改进图像配置和远程模式
- 更好的错误处理和用户反馈
2025-12-11 17:11:35 +08:00

196 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/** @type {import('next').NextConfig} */
const nextConfig = {
// 启用standalone输出,用于Docker部署
output: 'standalone',
// 服务器外部包配置(Next.js 16新配置)
serverExternalPackages: ['sharp', 'three', 'gsap'],
// Turbopack配置(Next.js 16默认启用)
turbopack: {},
// 图像优化配置
images: {
remotePatterns: [
{
protocol: 'http',
hostname: 'localhost',
port: '9000',
pathname: '/**',
},
{
protocol: 'http',
hostname: 'minio',
port: '9000',
pathname: '/**',
},
{
protocol: 'https',
hostname: 'threejs.org',
pathname: '/**',
}
],
unoptimized: true, // 在容器环境中禁用优化以提高性能
formats: ['image/webp', 'image/avif']
},
// 静态资源配置
assetPrefix: process.env.NODE_ENV === 'production' ? undefined : undefined,
// 压缩配置
compress: true,
// 性能优化
poweredByHeader: false,
generateEtags: false,
// Webpack配置
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// 支持3D文件格式
config.module.rules.push({
test: /\.(glb|gltf|fbx|obj|dae)$/,
type: 'asset/resource',
generator: {
filename: 'static/models/[name].[hash][ext]'
}
})
// 支持音频文件(用于3D场景)
config.module.rules.push({
test: /\.(mp3|wav|ogg)$/,
type: 'asset/resource',
generator: {
filename: 'static/audio/[name].[hash][ext]'
}
})
// 支持着色器文件
config.module.rules.push({
test: /\.(glsl|vs|fs|vert|frag)$/,
type: 'asset/source'
})
// 优化Three.js打包
if (!isServer) {
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false,
crypto: false
}
}
// 生产环境优化
if (!dev) {
// 启用代码分割
config.optimization.splitChunks = {
chunks: 'all',
cacheGroups: {
// Three.js单独打包
three: {
test: /[\\/]node_modules[\\/](three|@three)[\\/]/,
name: 'three',
chunks: 'all',
priority: 10
},
// GSAP单独打包
gsap: {
test: /[\\/]node_modules[\\/]gsap[\\/]/,
name: 'gsap',
chunks: 'all',
priority: 10
},
// 其他vendor库
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
priority: 5
}
}
}
}
return config
},
// 环境变量配置
env: {
CUSTOM_KEY: process.env.CUSTOM_KEY,
},
// 重定向配置
async redirects() {
return [
// 将根路径重定向到主页
{
source: '/home',
destination: '/',
permanent: true,
},
]
},
// 头部配置(安全性和性能)
async headers() {
return [
{
source: '/(.*)',
headers: [
// 安全头部
{
key: 'X-Frame-Options',
value: 'DENY'
},
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin'
},
// 3D资源缓存
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable'
}
],
},
{
// 3D模型文件特殊缓存策略
source: '/models/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=86400, s-maxage=31536000'
},
{
key: 'Access-Control-Allow-Origin',
value: '*'
}
],
},
{
// API路由CORS配置
source: '/api/:path*',
headers: [
{
key: 'Access-Control-Allow-Origin',
value: '*'
},
{
key: 'Access-Control-Allow-Methods',
value: 'GET, POST, PUT, DELETE, OPTIONS'
},
{
key: 'Access-Control-Allow-Headers',
value: 'Content-Type, Authorization'
}
],
}
]
}
}
module.exports = nextConfig