-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathnext.config.ts
53 lines (44 loc) · 1.5 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
import { removeUrlProtocol } from '@/utility/url';
import type { NextConfig } from 'next';
import { RemotePattern } from 'next/dist/shared/lib/image-config';
const VERCEL_BLOB_STORE_ID = process.env.BLOB_READ_WRITE_TOKEN?.match(
/^vercel_blob_rw_([a-z0-9]+)_[a-z0-9]+$/i,
)?.[1].toLowerCase();
const HOSTNAME_VERCEL_BLOB = VERCEL_BLOB_STORE_ID
? `${VERCEL_BLOB_STORE_ID}.public.blob.vercel-storage.com`
: undefined;
const HOSTNAME_CLOUDFLARE_R2 =
process.env.NEXT_PUBLIC_CLOUDFLARE_R2_PUBLIC_DOMAIN;
const HOSTNAME_AWS_S3 =
process.env.NEXT_PUBLIC_AWS_S3_BUCKET &&
process.env.NEXT_PUBLIC_AWS_S3_REGION
// eslint-disable-next-line max-len
? `${process.env.NEXT_PUBLIC_AWS_S3_BUCKET}.s3.${process.env.NEXT_PUBLIC_AWS_S3_REGION}.amazonaws.com`
: undefined;
const generateRemotePattern = (hostname: string) =>
({
protocol: 'https',
hostname: removeUrlProtocol(hostname)!,
port: '',
pathname: '/**',
} as const);
const remotePatterns: RemotePattern[] = [];
if (HOSTNAME_VERCEL_BLOB) {
remotePatterns.push(generateRemotePattern(HOSTNAME_VERCEL_BLOB));
}
if (HOSTNAME_CLOUDFLARE_R2) {
remotePatterns.push(generateRemotePattern(HOSTNAME_CLOUDFLARE_R2));
}
if (HOSTNAME_AWS_S3) {
remotePatterns.push(generateRemotePattern(HOSTNAME_AWS_S3));
}
const nextConfig: NextConfig = {
images: {
imageSizes: [200],
remotePatterns,
minimumCacheTTL: 31536000,
},
};
module.exports = process.env.ANALYZE === 'true'
? require('@next/bundle-analyzer')()(nextConfig)
: nextConfig;