-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnext.config.ts
71 lines (59 loc) · 1.61 KB
/
next.config.ts
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
/* eslint-disable sort-keys, @typescript-eslint/require-await */
import {type NextConfig} from 'next';
import {env} from 'node:process';
import {CDN_URL, IS_OFFLINE, IS_PRODUCTION, getSha} from './scripts/utils.mjs';
const exportMode = IS_OFFLINE || (!env.SELF_HOSTED && !env.VERCEL);
const skipLint = IS_OFFLINE || (IS_PRODUCTION && Boolean(env.SKIP_LINT));
const envKeys: (keyof NodeJS.ProcessEnv)[] = [
'ANALYTICS_API_URL',
'ANALYTICS_SCRIPT_URL',
'ANALYTICS_SITE_ID',
'BASE_URL',
'CDN_URL',
'ICP_FILING',
'OFFLINE',
'SELF_HOSTED',
'SHORT_LINK_URL',
'VERCEL',
'VERCEL_ENV',
'VERCEL_GIT_COMMIT_SHA',
];
const emptyEnvObject: Partial<NodeJS.ProcessEnv> = {};
const nextConfig: NextConfig = {
env: envKeys.reduce((acc, key) => {
acc[key] = env[key];
return acc;
}, emptyEnvObject),
// Hand over to Nginx and other web servers for reverse proxy and compression.
compress: !env.SELF_HOSTED,
// To generate a consistent build ID to use for CDN caching.
generateBuildId: getSha,
assetPrefix: env.VERCEL ? '' : CDN_URL,
reactStrictMode: true,
eslint: {
ignoreDuringBuilds: skipLint,
},
typescript: {
ignoreBuildErrors: skipLint,
},
};
if (exportMode) {
nextConfig.output = 'export';
} else {
nextConfig.headers = async () => {
const headers: Awaited<ReturnType<NonNullable<NextConfig['headers']>>> = [];
if (IS_PRODUCTION && !env.VERCEL) {
headers.push({
source: '/:all*(.gif|.ico|.png|.webp|.json|.txt|.js)',
headers: [
{
key: 'Cache-Control',
value: 'public, must-revalidate, max-age=2592000',
},
],
});
}
return headers;
};
}
export default nextConfig;