-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
180 lines (168 loc) · 6.36 KB
/
Copy pathnext.config.mjs
File metadata and controls
180 lines (168 loc) · 6.36 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
/** @type {import('next').NextConfig} */
const nextConfig = {
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
typescript: {
// Warning: This allows production builds to successfully complete even if
// your project has type errors.
ignoreBuildErrors: true,
},
// ⚡ PERFORMANCE: Next.js 15 optimizations for LLM applications
experimental: {
// Optimize package imports to reduce bundle size
optimizePackageImports: [
"@clerk/nextjs",
"lucide-react",
"framer-motion",
"@radix-ui/react-icons",
"react-icons",
],
},
// External packages for server components (moved from experimental)
serverExternalPackages: ["convex"],
onDemandEntries: {
// Period (in ms) where the server will keep pages in the buffer
maxInactiveAge: 25 * 1000,
// Number of pages that should be kept simultaneously without being disposed
pagesBufferLength: 2,
},
// Webpack optimizations for faster builds and smaller bundles
webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
// Split chunks more aggressively for better caching
if (!isServer && !dev) {
config.optimization.splitChunks = {
...config.optimization.splitChunks,
chunks: "all",
cacheGroups: {
...config.optimization.splitChunks.cacheGroups,
// Separate vendor chunks for better caching
clerk: {
name: "clerk",
test: /[\\/]node_modules[\\/]@clerk[\\/]/,
priority: 30,
chunks: "all",
},
ui: {
name: "ui",
test: /[\\/]node_modules[\\/](lucide-react|framer-motion|@radix-ui)[\\/]/,
priority: 25,
chunks: "all",
},
},
};
}
return config;
},
// Enable compression and optimization
compress: true,
poweredByHeader: false,
// Image optimization for better performance
images: {
formats: ["image/webp", "image/avif"],
minimumCacheTTL: 60,
},
// Rewrites to support PostHog
async rewrites() {
return [
{
source: "/ingest/static/:path*",
destination: "https://us-assets.i.posthog.com/static/:path*",
},
{
source: "/ingest/:path*",
destination: "https://us.i.posthog.com/:path*",
},
{
source: "/ingest/decide",
destination: "https://us.i.posthog.com/decide",
},
];
},
// This is required to support PostHog trailing slash API requests
skipTrailingSlashRedirect: true,
// Security headers
async headers() {
const isDev = process.env.NODE_ENV === "development";
// More permissive CSP for development to avoid CAPTCHA issues
const devCSP = [
"default-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:",
"script-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob: *",
"style-src 'self' 'unsafe-inline' *",
"img-src 'self' data: blob: *",
"connect-src 'self' data: blob: *",
"font-src 'self' data: *",
"media-src 'self' data: blob: *",
"frame-src 'self' *",
"worker-src 'self' blob: *",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self' *",
].join("; ");
// Production CSP with specific domains - fully permissive for reCAPTCHA
const prodCSP = [
"default-src 'self'",
"script-src 'self' 'unsafe-eval' 'unsafe-inline' *.posthog.com *.clerk.accounts.dev *.clerk.dev *.chained.chat *.clerk.com img.clerk.com clerk.chained.chat https://challenges.cloudflare.com https://www.gstatic.com https://www.google.com https://*.gstatic.com https://*.google.com https://*.recaptcha.net https://recaptcha.google.com https://www.googletagmanager.com https://*.googletagmanager.com worker.clerkprod-cloudflare.net clerk.services 'wasm-unsafe-eval'",
"worker-src 'self' blob:",
"style-src 'self' 'unsafe-inline' fonts.googleapis.com https://*.gstatic.com https://*.google.com https://recaptcha.google.com clerk.chained.chat",
"img-src 'self' data: blob: *.amazonaws.com *.convex.cloud *.clerk.accounts.dev *.clerk.dev *.chained.chat *.clerk.com img.clerk.com *.clerk.services clerk.chained.chat https://*.gstatic.com https://*.google.com https://*.googleusercontent.com https://recaptcha.google.com",
"connect-src 'self' *.convex.cloud *.posthog.com *.clerk.accounts.dev *.clerk.dev *.chained.chat *.clerk.com clerk.chained.chat accounts.google.com github.com api.github.com www.linkedin.com https://*.google.com https://*.recaptcha.net https://recaptcha.google.com https://*.googletagmanager.com https://*.gstatic.com worker.clerkprod-cloudflare.net clerk.services wss:",
"font-src 'self' fonts.gstatic.com https://*.google.com",
"media-src 'self' blob:",
"frame-src 'self' https://challenges.cloudflare.com https://*.google.com https://*.recaptcha.net https://recaptcha.google.com https://*.gstatic.com *.clerk.com clerk.chained.chat",
"child-src 'self' https://challenges.cloudflare.com https://*.google.com https://*.recaptcha.net https://recaptcha.google.com",
"object-src 'none'",
"base-uri 'self'",
"form-action 'self' accounts.google.com github.com www.linkedin.com *.clerk.com clerk.chained.chat",
"frame-ancestors 'none'",
"upgrade-insecure-requests",
].join("; ");
return [
{
source: "/(.*)",
headers: [
{
key: "Content-Security-Policy",
value: isDev ? devCSP : prodCSP,
},
{
key: "Strict-Transport-Security",
value: "max-age=31536000; includeSubDomains; preload",
},
{
key: "X-DNS-Prefetch-Control",
value: "on",
},
{
key: "X-Download-Options",
value: "noopen",
},
{
key: "X-Permitted-Cross-Domain-Policies",
value: "none",
},
],
},
{
source: "/api/(.*)",
headers: [
{
key: "Cache-Control",
value: "no-store, no-cache, must-revalidate, proxy-revalidate",
},
{
key: "Pragma",
value: "no-cache",
},
{
key: "Expires",
value: "0",
},
],
},
];
},
};
export default nextConfig;