From 21df39fe8ca482b2f02cdacbb186c86558ab9529 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 --- packages/now-next/src/index.ts | 26 ++++++++++++++------------ packages/now-next/src/utils.ts | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/packages/now-next/src/index.ts b/packages/now-next/src/index.ts index 7df103f7e9d..8850e45c6f5 100644 --- a/packages/now-next/src/index.ts +++ b/packages/now-next/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/packages/now-next/src/utils.ts b/packages/now-next/src/utils.ts index 2b00e85a812..2ccb2fb8ded 100644 --- a/packages/now-next/src/utils.ts +++ b/packages/now-next/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[]; };