Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support next/image with static exports #2563

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ export const onBuild = async (options: NetlifyPluginOptions) => {
await saveBuildCache(ctx)
}

// static exports only need to be uploaded to the CDN
// static exports only need to be uploaded to the CDN and setup /_next/image handler
if (ctx.buildConfig.output === 'export') {
return copyStaticExport(ctx)
return Promise.all([copyStaticExport(ctx), setImageConfig(ctx)])
}

await verifyAdvancedAPIRoutes(ctx)
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,21 @@ test('Renders the Home page correctly with output export and custom dist dir', a

await expectImageWasLoaded(page.locator('img'))
})

test.describe('next/image is using Netlify Image CDN', () => {
test('Local images', async ({ page, outputExport }) => {
const nextImageResponsePromise = page.waitForResponse('**/_next/image**')

await page.goto(`${outputExport.url}/image/local`)

const nextImageResponse = await nextImageResponsePromise
expect(nextImageResponse.request().url()).toContain('_next/image?url=%2Fsquirrel.jpg')

expect(nextImageResponse.status()).toBe(200)
// ensure next/image is using Image CDN
// source image is jpg, but when requesting it through Image CDN avif will be returned
expect(await nextImageResponse.headerValue('content-type')).toEqual('image/avif')

await expectImageWasLoaded(page.locator('img'))
})
})
10 changes: 10 additions & 0 deletions tests/fixtures/output-export/app/image/local/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Image from 'next/image'

export default function NextImageUsingNetlifyImageCDN() {
return (
<main>
<h1>Next/Image + Netlify Image CDN</h1>
<Image src="/squirrel.jpg" alt="a cute squirrel (next/image)" width={300} height={278} />
</main>
)
}
Loading