-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
115 lines (104 loc) · 3.04 KB
/
Copy pathnext.config.ts
File metadata and controls
115 lines (104 loc) · 3.04 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
import type { NextConfig } from "next";
// Bundle analyzer configuration
const withBundleAnalyzer = process.env.ANALYZE === 'true'
? require('@next/bundle-analyzer')({ enabled: true })
: (config: NextConfig) => config;
const nextConfig: NextConfig = {
// Enable React Strict Mode for better development experience
reactStrictMode: true,
// Enable experimental features for better performance
experimental: {
// Enable concurrent features
reactCompiler: false, // Set to true when stable
},
// Webpack optimizations for code splitting
webpack: (config, { dev, isServer }) => {
// Optimize for production builds
if (!dev && !isServer) {
// Split vendor modules for better caching
config.optimization.splitChunks = {
...config.optimization.splitChunks,
cacheGroups: {
...config.optimization.splitChunks.cacheGroups,
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
enforce: true,
},
common: {
name: 'commons',
minChunks: 2,
chunks: 'all',
enforce: true,
},
// Separate chunk for analytics/tracking
analytics: {
test: /[\\/]components[\\/](analytics|tracking)[\\/]/,
name: 'analytics',
chunks: 'all',
enforce: true,
},
// Separate chunk for UI components
ui: {
test: /[\\/]components[\\/]ui[\\/]/,
name: 'ui',
chunks: 'all',
enforce: true,
},
},
};
// Tree shaking optimizations
config.optimization.usedExports = true;
config.optimization.sideEffects = false;
}
return config;
},
// Performance optimizations
poweredByHeader: false,
compress: true,
// Image optimization
images: {
formats: ['image/webp', 'image/avif'],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
minimumCacheTTL: 31536000, // 1 year
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment',
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
// Headers for performance and security
async headers() {
return [
{
source: '/(.*)',
headers: [
// Cache control for static assets
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
// Preload critical resources
{
key: 'Link',
value: '</css/globals.css>; rel=preload; as=style',
},
],
},
{
source: '/api/(.*)',
headers: [
{
key: 'Cache-Control',
value: 'no-store, must-revalidate',
},
],
},
];
},
// Environment variables for build optimization
env: {
ENABLE_BUNDLE_ANALYZER: process.env.ANALYZE || 'false',
},
};
export default withBundleAnalyzer(nextConfig);