From 163f239904b6eb53f27d8577043cdc6d136928fd Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 24 Oct 2020 08:55:53 -0400 Subject: [PATCH] [next] Image Optimization for default loader (#5321) 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 https://github.com/vercel/next.js/issues/18122 --- src/index.ts | 26 ++++++++++++++------------ src/utils.ts | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7df103f7..8850e45c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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, @@ -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 diff --git a/src/utils.ts b/src/utils.ts index 2b00e85a..2ccb2fb8 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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[]; };