-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnext.config.ts
More file actions
126 lines (109 loc) · 3.44 KB
/
next.config.ts
File metadata and controls
126 lines (109 loc) · 3.44 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
import { cachingHeaders, optimizedImageMinimumCacheTTL } from '@/cache-control';
import bundleAnalyzer from '@next/bundle-analyzer';
import { withPayload } from '@payloadcms/next/withPayload';
import { withPostHogConfig } from '@posthog/nextjs-config';
import type { NextConfig } from 'next';
import type { Rewrite } from 'next/dist/lib/load-custom-routes';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env['ANALYZE'] === 'true',
openAnalyzer: true,
});
/**
* PostHog rewrites are required for the PostHog integration to work.
*
* In our production deployment we are using traefik as the reverse proxy
* redirects to PostHog are directly handled by traefik and will never
* reach the Next.js server. We keep these rewrites here for development
* and testing purposes.
*
*/
const postHogRewrites = (): Rewrite[] => {
return [
{
source: '/ingest/static/:path*',
destination: 'https://eu-assets.i.posthog.com/static/:path*',
},
{
source: '/ingest/:path*',
destination: 'https://eu.i.posthog.com/:path*',
},
{
source: '/ingest/decide',
destination: 'https://eu.i.posthog.com/decide',
},
];
};
const nextConfig: NextConfig = {
output: 'standalone',
serverExternalPackages: ['esbuild-wasm'],
productionBrowserSourceMaps: true,
transpilePackages: ['@t3-oss/env-nextjs', '@t3-oss/env-core'],
poweredByHeader: false,
reactStrictMode: true,
cacheComponents: true,
/**
* Our production deployment uses traefik as the reverse proxy and nginx for serving / caching
* static files. We compress the response in nginx to save CPU cycles on the Next.js server.
*/
compress: false,
...(process.env['NODE_ENV'] !== 'development' && {
cacheHandlers: {
default: require.resolve('./src/cache-handlers/default.cjs'),
},
}),
// enable react compiler for better error messages and performance
reactCompiler: true,
experimental: {
authInterrupts: true,
// Forward browser logs to the terminal for easier debugging
browserDebugInfoInTerminal: true,
// enable server source maps for better error tracking
serverSourceMaps: true,
// Enable filesystem caching for `next dev`
turbopackFileSystemCacheForDev: true,
staleTimes: {
dynamic: 0, // this must be set to 0 for payload to work correctly
static: 300, // 5 minutes for static pages, default
},
serverActions: {
bodySizeLimit: '10mb',
},
},
logging: { fetches: { fullUrl: true } },
images: {
minimumCacheTTL: optimizedImageMinimumCacheTTL,
formats: ['image/avif', 'image/webp'],
remotePatterns: [
{
protocol: 'https',
hostname: 'www.cevi.ch',
port: '',
},
],
},
rewrites: () => {
return {
beforeFiles: [
{
source: '/manifest.json',
destination: '/manifest.webmanifest',
},
],
afterFiles: [...postHogRewrites()],
};
},
headers: cachingHeaders,
};
const config = withBundleAnalyzer(withPayload(nextConfig, { devBundleServerPackages: false }));
export default process.env['POSTHOG_API_KEY']
? withPostHogConfig(config, {
personalApiKey: process.env['POSTHOG_API_KEY'],
projectId: process.env['POSTHOG_PROJECT_ID'] ?? '',
host: 'https://eu.posthog.com',
sourcemaps: {
deleteAfterUpload: false,
},
})
: config;