-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.js
More file actions
121 lines (111 loc) · 3.86 KB
/
next.config.js
File metadata and controls
121 lines (111 loc) · 3.86 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
import { withPayload } from '@payloadcms/next/withPayload'
import createNextIntlPlugin from 'next-intl/plugin'
import withBundleAnalyzer from '@next/bundle-analyzer'
const withNextIntl = createNextIntlPlugin()
import redirects from './redirects.js'
const NEXT_PUBLIC_SERVER_URL = process.env.VERCEL_PROJECT_PRODUCTION_URL
? `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`
: undefined || process.env.NEXT_PUBLIC_SERVER_URL || 'http://localhost:3000'
/** @type {import('next').NextConfig} */
const nextConfig = {
images: {
remotePatterns: [
...[NEXT_PUBLIC_SERVER_URL /* 'https://example.com' */].map((item) => {
const url = new URL(item)
return {
hostname: url.hostname,
protocol: url.protocol.replace(':', ''),
}
}),
],
// Enable image optimization
formats: ['image/webp', 'image/avif'],
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
// Enable lazy loading by default
dangerouslyAllowSVG: true,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
},
// Enable experimental features for better performance
experimental: {
// Enable optimized CSS loading
optimizeCss: true,
},
// Optimize JavaScript bundles
compiler: {
// Keep all console statements
removeConsole: false,
},
// Enable compression
compress: true,
reactStrictMode: true,
redirects,
// Security headers
async headers() {
return [
{
// Apply these headers to all routes
source: '/:path*',
headers: [
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'Content-Security-Policy',
value: `
default-src 'self';
script-src 'self' 'unsafe-inline' 'unsafe-eval' https://*.googletagmanager.com https://*.google-analytics.com https://connect.facebook.net https://www.facebook.com https://*.facebook.net;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
img-src 'self' data: blob: https://*.google-analytics.com https://*.googletagmanager.com https://www.facebook.com https://*.facebook.com https://*.facebook.net ${NEXT_PUBLIC_SERVER_URL};
font-src 'self' data: https://fonts.gstatic.com;
connect-src 'self' https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com https://www.facebook.com https://*.facebook.com https://connect.facebook.net https://*.facebook.net;
frame-src 'self' https://www.facebook.com https://*.facebook.com;
object-src 'none';
base-uri 'self';
form-action 'self' https://www.facebook.com https://*.facebook.com;
upgrade-insecure-requests;
`
.replace(/\s{2,}/g, ' ')
.trim(),
},
],
},
]
},
webpack: (config, { dev, isServer }) => {
config.resolve.alias.canvas = false
// Optimize bundle splitting
if (!dev && !isServer) {
config.optimization.splitChunks = {
chunks: 'all',
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
priority: 10,
reuseExistingChunk: true,
},
common: {
name: 'common',
minChunks: 2,
priority: 5,
reuseExistingChunk: true,
},
},
}
}
return config
},
}
// Enable bundle analyzer when ANALYZE env variable is set
const analyzeBundles = withBundleAnalyzer({
enabled: process.env.ANALYZE === 'true',
})
export default withNextIntl(analyzeBundles(withPayload(nextConfig)), {
devBundleServerPackages: false,
})