This repository was archived by the owner on Mar 24, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext.config.ts
More file actions
196 lines (182 loc) · 5.5 KB
/
next.config.ts
File metadata and controls
196 lines (182 loc) · 5.5 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
import { cpus } from 'node:os';
import type { NextConfig } from 'next';
import { withContentlayer } from 'next-contentlayer2';
import { initOpenNextCloudflareForDev } from '@opennextjs/cloudflare';
// Validate environment variables at build time
import './env';
const nextConfig: NextConfig = {
reactStrictMode: true,
poweredByHeader: false,
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx'],
productionBrowserSourceMaps: false,
// Performance optimizations
compress: true,
compiler: {
// Remove console logs for better performance in production
// removeConsole:
// process.env.NODE_ENV === 'production'
// ? true
// : {
// exclude: ['error', 'warn'],
// },
// Enable emotion optimization if used
emotion: true,
// Remove React properties in production
reactRemoveProperties: process.env.NODE_ENV === 'production',
},
// Build optimizations
eslint: {
ignoreDuringBuilds: true,
},
typescript: {
ignoreBuildErrors: process.env.NODE_ENV === 'production',
},
// Output configuration for better caching
output: 'standalone',
logging: {
fetches: {
fullUrl: true,
hmrRefreshes: true,
},
},
// Turbopack configuration moved from experimental
experimental: {
// mdxRs: true,
cssChunking: true,
// Optimize bundle analysis - disabled to prevent critters issues
// optimizeCss: true,
// Use SWC for faster compilation
swcTraceProfiling: false,
// Enable build worker threads
cpus: Math.max(1, Math.floor(cpus().length / 2)),
// Disable server minification for easier performance profiling
serverMinification: false,
// Disable server source maps to prevent esbuild errors in OpenNext/Cloudflare builds
serverSourceMaps: false,
// Optimize webpack memory usage (reduces max memory, may slightly increase build time)
webpackMemoryOptimizations: true,
},
// Performance profiling - disable webpack minification for better debugging
webpack: (config, { isServer }) => {
// Only disable minification in development for easier profiling
if (process.env.NODE_ENV === 'development') {
config.optimization.minimize = false;
}
// Ignore .map files to prevent esbuild errors in OpenNext/Cloudflare builds
// This prevents webpack from trying to process source map files
if (isServer) {
// Only apply to server-side builds (where OpenNext/esbuild processes files)
config.module.rules.push({
test: /\.map$/,
type: 'asset/source',
generator: {
emit: false, // Don't emit .map files
},
});
// Ignore .map files in module resolution
config.resolve.extensions = config.resolve.extensions.filter(
(ext: string) => ext !== '.map'
);
// Add ignore plugin to completely skip .map files
const { IgnorePlugin } = require('webpack');
config.plugins.push(
new IgnorePlugin({
resourceRegExp: /\.map$/,
})
);
}
return config;
},
// Add headers for API endpoints
async headers() {
return [
{
source: '/:path*',
headers: [
{ key: 'X-Frame-Options', value: 'DENY' },
{ key: 'Content-Security-Policy', value: "frame-ancestors 'none'" },
],
},
{
source: '/api/:path*',
headers: [
{ key: 'Access-Control-Allow-Credentials', value: 'true' },
{ key: 'Access-Control-Allow-Origin', value: '*' },
{ key: 'Access-Control-Allow-Methods', value: 'GET,POST,OPTIONS' },
{
key: 'Access-Control-Allow-Headers',
value:
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
},
],
},
];
},
// Add redirects
async redirects() {
return [
{
source: '/donate',
destination: '/contribute',
permanent: true,
},
{
source: '/get-involved',
destination: '/apply',
permanent: true,
},
{
source: '/roles',
destination: '/apply',
permanent: true,
},
{
source: '/careers',
destination: '/apply',
permanent: true,
},
];
},
// Image optimizations
images: {
remotePatterns: [
{
protocol: 'https' as const,
hostname: 'contrib.rocks',
},
{
protocol: 'https' as const,
hostname: 'allthingslinux.org',
},
{
protocol: 'https' as const,
hostname: 'dcbadge.limes.pink',
},
{
protocol: 'https' as const,
hostname: 'discord.gg',
},
{
protocol: 'https' as const,
hostname: 'i.imgur.com',
},
{
protocol: 'https' as const,
hostname: 'sprut.ai',
},
],
dangerouslyAllowSVG: true,
contentDispositionType: 'attachment' as const,
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
// Optimized image settings for better performance
formats: ['image/avif', 'image/webp'] as const,
// Reduced device sizes for faster processing
deviceSizes: [640, 828, 1200, 1920],
imageSizes: [16, 32, 48, 64, 96, 128, 256],
// Disable image optimization for Cloudflare Workers deployment
// Cloudflare Workers don't support Sharp, which is required for Next.js image optimization
unoptimized: true,
},
};
export default withContentlayer(nextConfig);
initOpenNextCloudflareForDev();