Skip to content

Commit

Permalink
[next] Image Optimization for default loader (#5321)
Browse files Browse the repository at this point in the history
We currently pass through `images` whenever its defined, but this is enabling Image Optimization in the Proxy for every Next.js project.

Instead, we should check to see if the default loader is used (the same use for `next dev`) as a signal to enable this feature in the deployment.

Related to vercel/next.js#18122
  • Loading branch information
styfle committed Oct 24, 2020
1 parent 3c55b54 commit 163f239
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/index.ts
Expand Up @@ -655,12 +655,13 @@ export const build = async ({

return {
output,
images: imagesManifest?.images
? {
domains: imagesManifest.images.domains,
sizes: imagesManifest.images.sizes,
}
: undefined,
images:
imagesManifest?.images?.loader === 'default'
? {
domains: imagesManifest.images.domains,
sizes: imagesManifest.images.sizes,
}
: undefined,
routes: [
// User headers
...headers,
Expand Down Expand Up @@ -1952,12 +1953,13 @@ export const build = async ({
};
})
: undefined,
images: imagesManifest?.images
? {
domains: imagesManifest.images.domains,
sizes: imagesManifest.images.sizes,
}
: undefined,
images:
imagesManifest?.images?.loader === 'default'
? {
domains: imagesManifest.images.domains,
sizes: imagesManifest.images.sizes,
}
: undefined,
/*
Desired routes order
- Runtime headers
Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Expand Up @@ -511,9 +511,12 @@ export async function getDynamicRoutes(
return routes;
}

type LoaderKey = 'imgix' | 'cloudinary' | 'akamai' | 'default';

type ImagesManifest = {
version: number;
images: {
loader: LoaderKey;
sizes: number[];
domains: string[];
};
Expand Down

0 comments on commit 163f239

Please sign in to comment.