-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
317 lines (299 loc) · 10.4 KB
/
Copy pathnext.config.ts
File metadata and controls
317 lines (299 loc) · 10.4 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/* eslint-disable @typescript-eslint/no-require-imports */
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
// Temporarily disable ESLint during build
eslint: {
ignoreDuringBuilds: true,
},
// Image optimization
images: {
formats: ['image/avif', 'image/webp'],
minimumCacheTTL: 60 * 60 * 24 * 30, // 30 days
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
remotePatterns: [
{
protocol: 'https',
hostname: 'picsum.photos',
},
{
protocol: 'https',
hostname: 'images.unsplash.com',
},
{
protocol: 'https',
hostname: 'plus.unsplash.com',
},
{
protocol: 'https',
hostname: 'source.unsplash.com',
},
{
protocol: 'https',
hostname: 'lh3.googleusercontent.com',
},
{
protocol: 'https',
hostname: 'avatars.githubusercontent.com',
},
{
protocol: 'https',
hostname: 'cdn.jsdelivr.net',
},
{
protocol: 'https',
hostname: 'cdnjs.cloudflare.com',
},
{
protocol: 'https',
hostname: 'imgs.search.brave.com',
},
],
},
// Enable compression
compress: true,
// PoweredBy header removal for security
poweredByHeader: false,
// Enable source maps for production debugging and Lighthouse analysis
productionBrowserSourceMaps: true,
// Headers for security, performance and caching
async headers() {
return [
{
// Security headers for all pages
source: '/(.*)',
headers: [
{
key: 'X-DNS-Prefetch-Control',
value: 'on'
},
{
key: 'X-Frame-Options',
value: 'DENY'
},
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'Referrer-Policy',
value: 'strict-origin-when-cross-origin'
},
{
key: 'Permissions-Policy',
value: process.env.NODE_ENV === 'development'
? 'camera=(), microphone=(), geolocation=(), gyroscope=(), magnetometer=(), payment=*'
: 'camera=(), microphone=(), geolocation=(), gyroscope=(), magnetometer=(), payment=(self "https://js.stripe.com" "https://checkout.stripe.com" "https://api.stripe.com" "https://hooks.stripe.com" "https://r.stripe.com")'
},
{
key: 'Strict-Transport-Security',
value: 'max-age=63072000; includeSubDomains; preload'
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin'
},
{
key: 'Content-Security-Policy',
value: (process.env.NODE_ENV === 'development' || process.env.VERCEL_ENV === 'preview')
? "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://js.stripe.com https://va.vercel-scripts.com; connect-src 'self' https://api.stripe.com https://r.stripe.com https://q.stripe.com https://m.stripe.com https://b.stripe.com https://js.stripe.com https://merchant-ui-api.stripe.com https://checkout.stripe.com https://vitals.vercel-insights.com https://va.vercel-scripts.com https://jbyuivzpetgbapisbnxy.supabase.co https://*.stripe.com; frame-src 'self' https://js.stripe.com https://hooks.stripe.com https://checkout.stripe.com; style-src 'self' 'unsafe-inline' https://js.stripe.com; img-src 'self' data: https: https://*.stripe.com; font-src 'self' data: https://js.stripe.com; object-src 'none'; base-uri 'self'; manifest-src 'self';"
: "default-src 'self'; script-src 'self' 'unsafe-inline' https://js.stripe.com https://va.vercel-scripts.com; connect-src 'self' https://api.stripe.com https://r.stripe.com https://q.stripe.com https://m.stripe.com https://b.stripe.com https://js.stripe.com https://merchant-ui-api.stripe.com https://checkout.stripe.com https://vitals.vercel-insights.com https://va.vercel-scripts.com https://jbyuivzpetgbapisbnxy.supabase.co https://*.stripe.com; frame-src 'self' https://js.stripe.com https://hooks.stripe.com https://checkout.stripe.com; style-src 'self' 'unsafe-inline' https://js.stripe.com; img-src 'self' data: https: https://*.stripe.com; font-src 'self' data: https://js.stripe.com; object-src 'none'; base-uri 'self'; manifest-src 'self';"
}
],
},
{
// Additional security for authentication pages
source: '/auth/(.*)',
headers: [
{
key: 'Cache-Control',
value: 'no-store, no-cache, must-revalidate, proxy-revalidate'
},
{
key: 'X-Robots-Tag',
value: 'noindex, nofollow, noarchive, nosnippet, noimageindex'
}
],
},
{
// Ensure main pages are indexable (override any global noindex)
source: '/((?!auth|api|_next|static).*)',
headers: [
{
key: 'X-Robots-Tag',
value: 'index, follow'
}
],
},
{
// API security headers
source: '/api/(.*)',
headers: [
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'X-Frame-Options',
value: 'DENY'
},
{
key: 'Cache-Control',
value: 'no-store, no-cache, must-revalidate'
}
],
},
{
// Cache static assets for 1 year
source: '/static/(.*)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable'
},
],
},
{
// Cache API responses briefly
source: '/api/(.*)',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=60, stale-while-revalidate=300'
},
],
},
];
},
// Force consistent port and set dynamic environment
env: {
NEXT_PUBLIC_APP_URL: process.env.NODE_ENV === 'production'
? 'https://localloopevents.xyz'
: 'http://localhost:3000',
},
// Webpack optimizations for performance
webpack: (config, { dev, isServer }) => {
// Suppress Supabase realtime-js warnings
const ignoreWarnings = [
...(config.ignoreWarnings || []),
{ module: /node_modules\/@supabase\/realtime-js/, message: /Critical dependency: the request of a dependency is an expression/ },
{ module: /realtime-js/, message: /Critical dependency: the request of a dependency is an expression/ },
];
config.ignoreWarnings = ignoreWarnings;
// Handle client-side only libraries
if (isServer) {
config.resolve = config.resolve || {}
config.resolve.fallback = {
...config.resolve.fallback,
'leaflet': false,
'react-leaflet': false,
'web-vitals': false,
'@vercel/analytics': false,
'@stripe/stripe-js': false,
'@stripe/react-stripe-js': false,
}
// Also exclude from externals
config.externals = config.externals || []
if (Array.isArray(config.externals)) {
config.externals.push(
'leaflet',
'react-leaflet',
'web-vitals',
'@vercel/analytics',
'@stripe/stripe-js',
'@stripe/react-stripe-js'
)
}
}
// Enhanced optimizations for both dev and production
if (!isServer) {
config.optimization = {
...config.optimization,
sideEffects: false,
minimize: !dev, // Only minimize in production
splitChunks: {
chunks: 'all',
maxInitialRequests: 25,
maxAsyncRequests: 25,
cacheGroups: {
// Separate Stripe into its own chunk for lazy loading
stripe: {
test: /[\\/]node_modules[\\/]@stripe/,
name: 'stripe',
chunks: 'all',
maxSize: 150000,
priority: 20,
},
// Separate large UI libraries
radix: {
test: /[\\/]node_modules[\\/]@radix-ui/,
name: 'radix-ui',
chunks: 'all',
maxSize: 100000,
priority: 15,
},
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
maxSize: 200000, // Reduced from 244KB
priority: 10,
},
common: {
name: 'common',
minChunks: 2,
chunks: 'all',
maxSize: 150000, // Reduced from 244KB
priority: 5,
},
},
},
}
}
// Performance optimizations for all builds (removed problematic React aliasing)
// Note: React aliasing was causing module resolution issues with jsx-runtime
// Bundle analyzer in development (optional)
if (dev && process.env.ANALYZE === 'true') {
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'server',
openAnalyzer: true,
})
);
}
return config;
},
// Experimental features for performance
experimental: {
optimizePackageImports: [
'lucide-react',
'@radix-ui/react-select',
'@radix-ui/react-checkbox',
'@radix-ui/react-label',
'@radix-ui/react-switch',
'@radix-ui/react-tabs',
'@stripe/stripe-js',
'@stripe/react-stripe-js',
'@supabase/ssr',
],
},
// Server external packages for better tree shaking
serverExternalPackages: ['@supabase/supabase-js'],
// Turbopack configuration - properly typed resolveAlias
turbopack: {
resolveAlias: {
// Use empty modules instead of false for proper typing
'react-leaflet': require.resolve('./lib/utils/empty-module.js'),
'leaflet': require.resolve('./lib/utils/empty-module.js'),
// Additional client-side only libraries
'web-vitals': require.resolve('./lib/utils/empty-module.js'),
'@vercel/analytics': require.resolve('./lib/utils/empty-module.js'),
'@stripe/stripe-js': require.resolve('./lib/utils/empty-module.js'),
'@stripe/react-stripe-js': require.resolve('./lib/utils/empty-module.js'),
},
},
};
export default nextConfig;