-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'canary' into 03-02-Add_test_for_router.refresh_preservi…
…ng_unaffected_segments
- Loading branch information
Showing
106 changed files
with
2,274 additions
and
757 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
docs/api-reference/next.config.js/custom-image-loader-config.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
--- | ||
description: Custom configuration for the next/image loader | ||
--- | ||
|
||
# Custom Image Loader Configuration | ||
|
||
If you want to use a cloud provider to optimize images instead of using the Next.js built-in Image Optimization API, you can configure `next.config.js` with the following: | ||
|
||
```js | ||
module.exports = { | ||
images: { | ||
loader: 'custom', | ||
loaderFile: './my/image/loader.js', | ||
}, | ||
} | ||
``` | ||
|
||
This `loaderFile` must point to a file relative to the root of your Next.js application. The file must export a default function that returns a string, for example: | ||
|
||
```js | ||
export default function myImageLoader({ src, width, quality }) { | ||
return `https://example.com/${src}?w=${width}&q=${quality || 75}` | ||
} | ||
``` | ||
|
||
Alternatively, you can use the [`loader` prop](/docs/api-reference/next/image.md#loader) to pass the function to each instance of `next/image`. | ||
|
||
## Example Loader Configuration | ||
|
||
- [Akamai](#akamai) | ||
- [Cloudinary](#cloudinary) | ||
- [Cloudflare](#cloudflare) | ||
- [Contentful](#contentful) | ||
- [Fastly](#fastly) | ||
- [Gumlet](#gumlet) | ||
- [ImageEngine](#imageengine) | ||
- [Imgix](#imgix) | ||
- [Thumbor](#thumbor) | ||
|
||
### Akamai | ||
|
||
```js | ||
// Docs: https://techdocs.akamai.com/ivm/reference/test-images-on-demand | ||
export default function akamaiLoader({ src, width, quality }) { | ||
return `https://example.com/${src}?imwidth=${width}` | ||
} | ||
``` | ||
|
||
### Cloudinary | ||
|
||
```js | ||
// Demo: https://res.cloudinary.com/demo/image/upload/w_300,c_limit,q_auto/turtles.jpg | ||
export default function cloudinaryLoader({ src, width, quality }) { | ||
const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`] | ||
return `https://example.com/${params.join(',')}${src}` | ||
} | ||
``` | ||
|
||
### Cloudflare | ||
|
||
```js | ||
// Docs: https://developers.cloudflare.com/images/url-format | ||
export default function cloudflareLoader({ src, width, quality }) { | ||
const params = [`width=${width}`, `quality=${quality || 75}`, 'format=auto'] | ||
return `https://example.com/cdn-cgi/image/${params.join(',')}/${src}` | ||
} | ||
``` | ||
|
||
### Contentful | ||
|
||
```js | ||
// Docs: https://www.contentful.com/developers/docs/references/images-api/ | ||
export default function contentfulLoader({ src, quality, width }) { | ||
const url = new URL(`https://example.com${src}`) | ||
url.searchParams.set('fm', 'webp') | ||
url.searchParams.set('w', width.toString()) | ||
url.searchParams.set('q', quality.toString() || '75') | ||
return url.href | ||
} | ||
``` | ||
|
||
## Fastly | ||
|
||
```js | ||
// Docs: https://developer.fastly.com/reference/io/ | ||
export default function fastlyLoader({ src, width, quality }) { | ||
const url = new URL(`https://example.com${src}`) | ||
url.searchParams.set('auto', 'webp') | ||
url.searchParams.set('width', width.toString()) | ||
url.searchParams.set('quality', quality.toString() || '75') | ||
return url.href | ||
} | ||
``` | ||
|
||
## Gumlet | ||
|
||
```js | ||
// Docs: https://docs.gumlet.com/reference/image-transform-size | ||
export default function gumletLoader({ src, width, quality }) { | ||
const url = new URL(`https://example.com${src}`) | ||
url.searchParams.set('format', 'auto') | ||
url.searchParams.set('w', width.toString()) | ||
url.searchParams.set('q', quality.toString() || '75') | ||
return url.href | ||
} | ||
``` | ||
|
||
### ImageEngine | ||
|
||
```js | ||
// Docs: https://support.imageengine.io/hc/en-us/articles/360058880672-Directives | ||
export default function imageengineLoader({ src, width, quality }) { | ||
const compression = 100 - (quality || 50) | ||
const params = [`w_${width}`, `cmpr_${compression}`)] | ||
return `https://example.com${src}?imgeng=/${params.join('/')` | ||
} | ||
``` | ||
### Imgix | ||
```js | ||
// Demo: https://static.imgix.net/daisy.png?format=auto&fit=max&w=300 | ||
export default function imgixLoader({ src, width, quality }) { | ||
const url = new URL(`https://example.com${src}`) | ||
const params = url.searchParams | ||
params.set('auto', params.getAll('auto').join(',') || 'format') | ||
params.set('fit', params.get('fit') || 'max') | ||
params.set('w', params.get('w') || width.toString()) | ||
params.set('q', quality.toString() || '50') | ||
return url.href | ||
} | ||
``` | ||
|
||
### Thumbor | ||
|
||
```js | ||
// Docs: https://thumbor.readthedocs.io/en/latest/ | ||
export default function thumborLoader({ src, width, quality }) { | ||
const params = [`${width}x0`, `filters:quality(${quality || 75})`] | ||
return `https://example.com${params.join('/')}${src}` | ||
} | ||
``` | ||
|
||
## Related | ||
|
||
<div class="card"> | ||
<a href="/docs/basic-features/image-optimization.md"> | ||
<b>Image Optimization</b> | ||
<small>Learn how to optimize images with the Image component.</small> | ||
</a> | ||
</div> | ||
|
||
<div class="card"> | ||
<a href="/docs/api-reference/next.config.js/introduction.md"> | ||
<b>Introduction to next.config.js:</b> | ||
<small>Learn more about the configuration file used by Next.js.</small> | ||
</a> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,5 @@ | |
"registry": "https://registry.npmjs.org/" | ||
} | ||
}, | ||
"version": "13.2.3" | ||
"version": "13.2.4-canary.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "create-next-app", | ||
"version": "13.2.3", | ||
"version": "13.2.4-canary.1", | ||
"keywords": [ | ||
"react", | ||
"next", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.