Skip to content

Commit

Permalink
Update default configuration to match image optimization (#17943)
Browse files Browse the repository at this point in the history
Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
timneutkens and styfle committed Oct 16, 2020
1 parent dfcf267 commit 4f59209
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions packages/next/client/image.tsx
Expand Up @@ -52,7 +52,7 @@ function computeSrc(src: string, host: string, unoptimized: boolean): string {

function callLoader(src: string, host: string, width?: number): string {
let loader = loaders[imageData.hosts[host].loader || 'default']
return loader({ root: imageData.hosts[host].path, filename: src, width })
return loader({ root: imageData.hosts[host].path, src, width })
}

type SrcSetData = {
Expand Down Expand Up @@ -166,18 +166,19 @@ export default function Image({

type LoaderProps = {
root: string
filename: string
src: string
width?: number
}

function imgixLoader({ root, filename, width }: LoaderProps): string {
return `${root}${filename}${width ? '?w=' + width : ''}`
function imgixLoader({ root, src, width }: LoaderProps): string {
return `${root}${src}${width ? '?w=' + width : ''}`
}

function cloudinaryLoader({ root, filename, width }: LoaderProps): string {
return `${root}${width ? 'w_' + width + '/' : ''}${filename}`
function cloudinaryLoader({ root, src, width }: LoaderProps): string {
return `${root}${width ? 'w_' + width + '/' : ''}${src}`
}

function defaultLoader({ root, filename }: LoaderProps): string {
return `${root}${filename}`
function defaultLoader({ root, src, width }: LoaderProps): string {
// TODO: change quality parameter to be configurable
return `${root}?url=${encodeURIComponent(src)}&width=${width}&q=100`
}
2 changes: 1 addition & 1 deletion packages/next/next-server/server/config.ts
Expand Up @@ -26,7 +26,7 @@ const defaultConfig: { [key: string]: any } = {
images: {
sizes: [320, 420, 768, 1024, 1200],
domains: [],
hosts: { default: { path: 'defaultconfig' } },
hosts: { default: { path: '/_next/image' } },
},
devIndicators: {
buildActivity: true,
Expand Down

0 comments on commit 4f59209

Please sign in to comment.