Skip to content

Commit

Permalink
Fix image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
josepjaume committed Sep 16, 2021
1 parent 8453614 commit 5710beb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 15 additions & 1 deletion components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import Image, { ImageProps } from 'next/image'

const loader = ({ src }) => {
return `${process.env.basePath}/${src}`
}

function CustomImage(props: ImageProps): JSX.Element {
const { src } = props
let url = src

if (typeof src === 'object' && 'src' in src) {
url = {
...src,
src: `${process.env.basePath}${src.src}`,
}
}

// eslint-disable-next-line jsx-a11y/alt-text, react/jsx-props-no-spreading
return <Image unoptimized {...props} />
return <Image unoptimized {...props} loader={loader} src={url} />
}

export default CustomImage
10 changes: 6 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const securityHeaders = [
},
]

const basePath = process.env.BASE_PATH || '/'
const basePath = process.env.BASE_PATH || ''

/**
* @type {import('next/dist/server/config').NextConfig}
Expand All @@ -22,16 +22,18 @@ const nextConfig = {
target: 'serverless',
distDir: 'dist',
basePath,
async headers() {
return [{ source: '/:path*', headers: securityHeaders }]
env: {
basePath: process.env.BASE_PATH,
},
assetPrefix: basePath,
images: {
loader: 'custom',
path: basePath,
deviceSizes: [640, 750, 828, 1080, 1200, 1920, 2048, 3840],
imageSizes: [16, 32, 48, 64, 96, 128, 256, 384],
},
async headers() {
return [{ source: '/:path*', headers: securityHeaders }]
},
future: {},
sassOptions: {
prependData: `@import "styles/variables"; @import "styles/mixins";`,
Expand Down

0 comments on commit 5710beb

Please sign in to comment.