Skip to content

Commit 65916fe

Browse files
committed
fix: 🐛 Correctly pass basePath to src and srcSet
1 parent a64c2cd commit 65916fe

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

__tests__/components/image/config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* @type {import('../../../src/utils/getConfig').Config}
33
*/
44
const config = {
5+
basePath: '/base-path',
56
imageDir: '_custom-optimize',
67
filenameGenerator: ({ path, name, width, quality, extension }) => `${path}-${name}.${width}.${quality}.${extension}`,
78
convertFormat: [

__tests__/components/image/config.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ describe('Apply config', () => {
1212
test('Set `imageDir` and `filenameGenerator` and `convetFormat`', () => {
1313
render(<CustomImage src="/images/img.png" width={1920} height={1280} priority />)
1414

15-
expect(screen.getByRole('img').getAttribute('src')).toBe('/_custom-optimize/images-img.3840.75.webp')
15+
expect(screen.getByRole('img').getAttribute('src')).toBe('/base-path/_custom-optimize/images-img.3840.75.webp')
1616
})
1717
})

src/image.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const exportableLoader: ImageLoader = ({ src: _src, width, quality }) => {
6262
)
6363
}
6464

65-
return output
65+
return `${config.basePath ?? ''}${output}`
6666
}
6767

6868
const CustomImage = (props: ImageProps) => {

0 commit comments

Comments
 (0)