Move next.config to TypeScript
This commit is contained in:
parent
cf28267fe0
commit
3875c1ab1e
@ -1,3 +1,7 @@
|
|||||||
|
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||||
|
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(
|
const VERCEL_BLOB_STORE_ID = process.env.BLOB_READ_WRITE_TOKEN?.match(
|
||||||
/^vercel_blob_rw_([a-z0-9]+)_[a-z0-9]+$/i,
|
/^vercel_blob_rw_([a-z0-9]+)_[a-z0-9]+$/i,
|
||||||
)?.[1].toLowerCase();
|
)?.[1].toLowerCase();
|
||||||
@ -16,23 +20,27 @@ const HOSTNAME_AWS_S3 =
|
|||||||
? `${process.env.NEXT_PUBLIC_AWS_S3_BUCKET}.s3.${process.env.NEXT_PUBLIC_AWS_S3_REGION}.amazonaws.com`
|
? `${process.env.NEXT_PUBLIC_AWS_S3_BUCKET}.s3.${process.env.NEXT_PUBLIC_AWS_S3_REGION}.amazonaws.com`
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
const createRemotePattern = (hostname) => hostname
|
const generateRemotePattern = (hostname: string) =>
|
||||||
? {
|
({ protocol: 'https', hostname, port: '', pathname: '/**' } as const);
|
||||||
protocol: 'https',
|
|
||||||
hostname,
|
|
||||||
port: '',
|
|
||||||
pathname: '/**',
|
|
||||||
}
|
|
||||||
: [];
|
|
||||||
|
|
||||||
/** @type {import('next').NextConfig} */
|
const generateRemotePatterns = () => {
|
||||||
const nextConfig = {
|
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));
|
||||||
|
}
|
||||||
|
return remotePatterns;
|
||||||
|
};
|
||||||
|
|
||||||
|
const nextConfig: NextConfig = {
|
||||||
images: {
|
images: {
|
||||||
imageSizes: [200],
|
imageSizes: [200],
|
||||||
remotePatterns: []
|
remotePatterns: generateRemotePatterns(),
|
||||||
.concat(createRemotePattern(HOSTNAME_VERCEL_BLOB))
|
|
||||||
.concat(createRemotePattern(HOSTNAME_CLOUDFLARE_R2))
|
|
||||||
.concat(createRemotePattern(HOSTNAME_AWS_S3)),
|
|
||||||
minimumCacheTTL: 31536000,
|
minimumCacheTTL: 31536000,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue
Block a user