Skip to content

Commit 302ba1b

Browse files
avoid ternaries in next.config.mjs
1 parent a259564 commit 302ba1b

File tree

1 file changed

+66
-55
lines changed

1 file changed

+66
-55
lines changed

apps/site/next.config.mjs

Lines changed: 66 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,7 @@ const nextConfig = {
1717
// is being built on a subdirectory (e.g. /nodejs-website)
1818
basePath: BASE_PATH,
1919
// Vercel/Next.js Image Optimization Settings
20-
images:
21-
// If we're building for the Cloudflare deployment we want to use the custom cloudflare image loader
22-
//
23-
// Important: The custom loader ignores `remotePatterns` as those are configured as allowed source origins
24-
// (https://developers.cloudflare.com/images/transform-images/sources/)
25-
// in the Cloudflare dashboard itself instead (to the exact same values present in `remotePatterns` below).
26-
//
27-
OPEN_NEXT_CLOUDFLARE
28-
? {
29-
loader: 'custom',
30-
loaderFile: './cloudflare-image-loader.ts',
31-
}
32-
: {
33-
// We disable image optimisation during static export builds
34-
unoptimized: ENABLE_STATIC_EXPORT,
35-
// We add it to the remote pattern for the static images we use from multiple sources
36-
// to be marked as safe sources (these come from Markdown files)
37-
remotePatterns: [
38-
{
39-
protocol: 'https',
40-
hostname: 'avatars.githubusercontent.com',
41-
port: '',
42-
pathname: '/**',
43-
},
44-
{
45-
protocol: 'https',
46-
hostname: 'bestpractices.coreinfrastructure.org',
47-
port: '',
48-
pathname: '/**',
49-
},
50-
{
51-
protocol: 'https',
52-
hostname: 'raw.githubusercontent.com',
53-
port: '',
54-
pathname: '/nodejs/**',
55-
},
56-
{
57-
protocol: 'https',
58-
hostname: 'user-images.githubusercontent.com',
59-
port: '',
60-
pathname: '/**',
61-
},
62-
{
63-
protocol: 'https',
64-
hostname: 'website-assets.oramasearch.com',
65-
port: '',
66-
pathname: '/**',
67-
},
68-
],
69-
},
20+
images: getImagesConfig(),
7021
serverExternalPackages: ['twoslash'],
7122
outputFileTracingIncludes: {
7223
// Twoslash needs TypeScript declarations to function, and, by default, Next.js
@@ -122,12 +73,72 @@ const nextConfig = {
12273
'shiki',
12374
],
12475
},
125-
// If we're building for the Cloudflare deployment we want to set
126-
// an appropriate deploymentId (needed for skew protection)
127-
deploymentId: OPEN_NEXT_CLOUDFLARE
128-
? (await import('@opennextjs/cloudflare')).getDeploymentId()
129-
: undefined,
76+
deploymentId: await getDeploymentId(),
13077
};
13178

79+
function getImagesConfig() {
80+
if (OPEN_NEXT_CLOUDFLARE) {
81+
// If we're building for the Cloudflare deployment we want to use the custom cloudflare image loader
82+
//
83+
// Important: The custom loader ignores `remotePatterns` as those are configured as allowed source origins
84+
// (https://developers.cloudflare.com/images/transform-images/sources/)
85+
// in the Cloudflare dashboard itself instead (to the exact same values present in `remotePatterns` below).
86+
//
87+
return {
88+
loader: 'custom',
89+
loaderFile: './cloudflare-image-loader.ts',
90+
};
91+
}
92+
93+
return {
94+
// We disable image optimisation during static export builds
95+
unoptimized: ENABLE_STATIC_EXPORT,
96+
// We add it to the remote pattern for the static images we use from multiple sources
97+
// to be marked as safe sources (these come from Markdown files)
98+
remotePatterns: [
99+
{
100+
protocol: 'https',
101+
hostname: 'avatars.githubusercontent.com',
102+
port: '',
103+
pathname: '/**',
104+
},
105+
{
106+
protocol: 'https',
107+
hostname: 'bestpractices.coreinfrastructure.org',
108+
port: '',
109+
pathname: '/**',
110+
},
111+
{
112+
protocol: 'https',
113+
hostname: 'raw.githubusercontent.com',
114+
port: '',
115+
pathname: '/nodejs/**',
116+
},
117+
{
118+
protocol: 'https',
119+
hostname: 'user-images.githubusercontent.com',
120+
port: '',
121+
pathname: '/**',
122+
},
123+
{
124+
protocol: 'https',
125+
hostname: 'website-assets.oramasearch.com',
126+
port: '',
127+
pathname: '/**',
128+
},
129+
],
130+
};
131+
}
132+
133+
async function getDeploymentId() {
134+
if (OPEN_NEXT_CLOUDFLARE) {
135+
// If we're building for the Cloudflare deployment we want to set
136+
// an appropriate deploymentId (needed for skew protection)
137+
return await import('@opennextjs/cloudflare').getDeploymentId();
138+
}
139+
140+
return undefined;
141+
}
142+
132143
const withNextIntl = createNextIntlPlugin('./i18n.tsx');
133144
export default withNextIntl(nextConfig);

0 commit comments

Comments
 (0)