This repository was archived by the owner on Jul 7, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
204 lines (186 loc) · 5.29 KB
/
Copy pathnext.config.js
File metadata and controls
204 lines (186 loc) · 5.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/** @type {import('next').NextConfig} */
const withPWA = require('@ducanh2912/next-pwa').default
const bundleAnalyzer = require('@next/bundle-analyzer')
const path = require('path')
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})
const shaderTest = /\.(wgsl|glsl|vert|frag)$/i
const audioTest = /\.(mp3|wav|ogg)$/i
const csp = [
"default-src 'self'", // load everything from same origin by default
"base-uri 'self'",
"frame-ancestors 'none'",
"object-src 'none'",
"font-src 'self' data:",
"img-src 'self' data: blob:",
"media-src 'self' data: blob:",
"script-src 'self' 'unsafe-eval' 'unsafe-inline'",
"style-src 'self' 'unsafe-inline'",
"connect-src 'self' https: ws: wss: blob:",
"worker-src 'self' blob:",
'upgrade-insecure-requests',
].join('; ')
const securityHeaders = [
{ key: 'Content-Security-Policy', value: csp },
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'X-Content-Type-Options', value: 'nosniff' },
{ key: 'Referrer-Policy', value: 'origin-when-cross-origin' },
{ key: 'Permissions-Policy', value: 'accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()' },
{ key: 'Strict-Transport-Security', value: 'max-age=31536000; includeSubDomains' },
{ key: 'Cross-Origin-Embedder-Policy', value: 'require-corp' },
{ key: 'Cross-Origin-Opener-Policy', value: 'same-origin' },
{ key: 'Cross-Origin-Resource-Policy', value: 'cross-origin' },
{ key: 'X-XSS-Protection', value: '1; mode=block' },
]
const nextConfig = {
// Enable experimental features for better performance
experimental: {
webpackBuildWorker: true,
optimizeCss: true,
optimizePackageImports: ['three', '@react-three/fiber', '@react-three/drei'],
},
// TypeScript configuration
typescript: {
ignoreBuildErrors: false,
},
// ESLint configuration
eslint: {
ignoreDuringBuilds: false,
dirs: ['app', 'src', 'tests'],
},
// Image optimization
images: {
formats: ['image/webp', 'image/avif'],
minimumCacheTTL: 31536000,
},
// Headers for SharedArrayBuffer and WebGPU
async headers() {
return [
{
source: '/(.*)',
headers: securityHeaders,
},
]
},
// Rewrites for API routes
async rewrites() {
return [
{
source: '/api/health',
destination: '/api/health',
},
]
},
// Compression
compress: true,
poweredByHeader: false,
reactStrictMode: true,
// swcMinify is now default in Next.js 15
// Use standalone only in production builds, not for development/testing
...(process.env.NODE_ENV === 'production' && !process.env.CI ? { output: 'standalone' } : {}),
// Webpack configuration for WebGPU and shader support
webpack: (config, { dev, isServer }) => {
config.module.rules.push(
{
test: shaderTest,
type: 'asset/source',
},
{
test: audioTest,
type: 'asset/resource',
generator: {
filename: 'static/sounds/[name].[contenthash][ext]',
},
}
)
// Resolve aliases
config.resolve.alias = {
...config.resolve.alias,
'@': path.resolve(process.cwd(), 'src'),
'@lib/logger': path.resolve(
process.cwd(),
isServer ? 'src/lib/logger.server.ts' : 'src/lib/logger.client.ts'
),
}
// Optimization for Three.js
if (!dev && !isServer) {
// Enhanced bundle splitting for client-side
config.optimization.splitChunks = {
chunks: 'all',
minSize: 20000,
maxSize: 100000,
maxAsyncSize: 200000,
cacheGroups: {
default: {
minChunks: 2,
priority: -20,
reuseExistingChunk: true
},
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
priority: -10,
chunks: 'all'
},
three: {
test: /[\\/]node_modules[\\/](three|@react-three)[\\/]/,
name: 'three',
priority: 20,
chunks: 'all',
enforce: true
},
tone: {
test: /[\\/]node_modules[\\/]tone[\\/]/,
name: 'tone',
priority: 20,
chunks: 'async',
enforce: true
},
magenta: {
test: /[\\/]node_modules[\\/]@magenta[\\/]/,
name: 'magenta',
priority: 25,
chunks: 'async',
enforce: true
},
ui: {
test: /[\\/]node_modules[\\/](gsap|framer-motion|@radix-ui)[\\/]/,
name: 'ui',
priority: 10,
chunks: 'all',
enforce: true,
},
}
}
}
// WebGPU polyfill configuration
config.resolve.fallback = {
...config.resolve.fallback,
fs: false,
path: false,
crypto: false,
}
return config
},
}
// PWA configuration
const pwaConfig = {
dest: 'public',
register: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: /^https?.*/,
handler: 'NetworkFirst',
options: {
cacheName: 'offlineCache',
expiration: {
maxEntries: 200,
},
},
},
],
buildExcludes: [/middleware-manifest.json$/],
}
module.exports = withBundleAnalyzer(withPWA(pwaConfig)(nextConfig))