Skip to content

Commit 7814ab7

Browse files
fix: image loading issues
1 parent 43f5c5b commit 7814ab7

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

website/next.config.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import type { NextConfig } from "next";
33
const isProd = process.env.NODE_ENV === "production";
44
const nextConfig: NextConfig = {
55
output: "export",
6-
images: { unoptimized: true },
7-
assetPrefix: isProd ? "/Passcodes/" : "",
6+
images: {
7+
loader: "custom",
8+
loaderFile: "src/libs/custom-image-loader.ts",
9+
},
810
basePath: isProd ? "/Passcodes" : "",
11+
assetPrefix: isProd ? "/Passcodes/" : "",
912
};
1013

1114
export default nextConfig;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// custom-image-loader.js
2+
// Code: https://stackoverflow.com/a/78220610
3+
4+
import nextConfig from "../../next.config";
5+
import path from "path";
6+
7+
const basePath = nextConfig.basePath;
8+
9+
export default function myImageLoader({
10+
src,
11+
width,
12+
}: {
13+
src: string;
14+
width: string;
15+
}) {
16+
if (basePath && path.isAbsolute(src)) {
17+
return `${basePath}${src}?width=${width}`;
18+
}
19+
return `${src}?width=${width}`;
20+
}

0 commit comments

Comments
 (0)