Skip to content

Commit d4d116a

Browse files
move getImagesConfig to its own file
1 parent 2a984f8 commit d4d116a

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

apps/site/next.config.mjs

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,9 @@ import {
66
ENABLE_STATIC_EXPORT,
77
OPEN_NEXT_CLOUDFLARE,
88
} from './next.constants.mjs';
9+
import { getImagesConfig } from './next.image.config.mjs';
910
import { redirects, rewrites } from './next.rewrites.mjs';
1011

11-
const getImagesConfig = () => {
12-
if (OPEN_NEXT_CLOUDFLARE) {
13-
// If we're building for the Cloudflare deployment we want to use the custom cloudflare image loader
14-
//
15-
// Important: The custom loader ignores `remotePatterns` as those are configured as allowed source origins
16-
// (https://developers.cloudflare.com/images/transform-images/sources/)
17-
// in the Cloudflare dashboard itself instead (to the exact same values present in `remotePatterns` below).
18-
//
19-
return {
20-
loader: 'custom',
21-
loaderFile: './cloudflare/image-loader.ts',
22-
};
23-
}
24-
25-
return {
26-
// We disable image optimisation during static export builds
27-
unoptimized: ENABLE_STATIC_EXPORT,
28-
// We add it to the remote pattern for the static images we use from multiple sources
29-
// to be marked as safe sources (these come from Markdown files)
30-
remotePatterns: [
31-
new URL('https://avatars.githubusercontent.com/**'),
32-
new URL('https://bestpractices.coreinfrastructure.org/**'),
33-
new URL('https://raw.githubusercontent.com/nodejs/**'),
34-
new URL('https://user-images.githubusercontent.com/**'),
35-
new URL('https://website-assets.oramasearch.com/**'),
36-
],
37-
};
38-
};
39-
4012
const getDeploymentId = async () => {
4113
if (OPEN_NEXT_CLOUDFLARE) {
4214
// If we're building for the Cloudflare deployment we want to set

apps/site/next.image.config.mjs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {
2+
ENABLE_STATIC_EXPORT,
3+
OPEN_NEXT_CLOUDFLARE,
4+
} from './next.constants.mjs';
5+
6+
export const getImagesConfig = () => {
7+
if (OPEN_NEXT_CLOUDFLARE) {
8+
// If we're building for the Cloudflare deployment we want to use the custom cloudflare image loader
9+
//
10+
// Important: The custom loader ignores `remotePatterns` as those are configured as allowed source origins
11+
// (https://developers.cloudflare.com/images/transform-images/sources/)
12+
// in the Cloudflare dashboard itself instead (to the exact same values present in `remotePatterns` below).
13+
//
14+
return {
15+
loader: 'custom',
16+
loaderFile: './cloudflare/image-loader.ts',
17+
};
18+
}
19+
20+
return {
21+
// We disable image optimisation during static export builds
22+
unoptimized: ENABLE_STATIC_EXPORT,
23+
// We add it to the remote pattern for the static images we use from multiple sources
24+
// to be marked as safe sources (these come from Markdown files)
25+
remotePatterns: [
26+
new URL('https://avatars.githubusercontent.com/**'),
27+
new URL('https://bestpractices.coreinfrastructure.org/**'),
28+
new URL('https://raw.githubusercontent.com/nodejs/**'),
29+
new URL('https://user-images.githubusercontent.com/**'),
30+
new URL('https://website-assets.oramasearch.com/**'),
31+
],
32+
};
33+
};

0 commit comments

Comments
 (0)