-
Notifications
You must be signed in to change notification settings - Fork 27k
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 record/new-features
- Loading branch information
Showing
86 changed files
with
1,816 additions
and
325 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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
description: Enable Image Optimization with the built-in Image component. | ||
--- | ||
|
||
# next/image | ||
|
||
<details> | ||
<summary><b>Examples</b></summary> | ||
<ul> | ||
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/image-component">Image Component</a></li> | ||
</ul> | ||
</details> | ||
|
||
> Before moving forward, we recommend you to read [Image Optimization](/docs/basic-features/image-optimization.md) first. | ||
Image Optimization can be enabled via the `Image` component exported by `next/image`. | ||
|
||
For an example, consider a project with the following files: | ||
|
||
- `pages/index.js` | ||
- `public/me.png` | ||
|
||
We can serve an optimized image like so: | ||
|
||
```jsx | ||
import Image from 'next/image' | ||
|
||
function Home() { | ||
return ( | ||
<> | ||
<h1>My Homepage</h1> | ||
<Image | ||
src="/me.png" | ||
alt="Picture of the author" | ||
width={500} | ||
height={500} | ||
/> | ||
<p>Welcome to my homepage!</p> | ||
</> | ||
) | ||
} | ||
|
||
export default Home | ||
``` | ||
|
||
`Image` accepts the following props: | ||
|
||
- `src` - The path or URL to the source image. This is required. | ||
- `width` - The intrinsic width of the source image in pixels. Must be an integer without a unit. Required unless `unsized` is true. | ||
- `height` - The intrinsic height of the source image, in pixels. Must be an integer without a unit. Required unless `unsized` is true. | ||
- `sizes` - Defines what proportion of the screen you expect the image to take up. Recommended, as it helps serve the correct sized image to each device. [More info](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-sizes). | ||
- `quality` - The quality of the optimized image, an integer between 1 and 100 where 100 is the best quality. Default 75. | ||
- `loading` - The loading behavior. When `lazy`, defer loading the image until it reaches a calculated distance from the viewport. When `eager`, load the image immediately. Default `lazy`. [More info](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img#attr-loading) | ||
- `priority` - When true, the image will be considered high priority and [preload](https://web.dev/preload-responsive-images/). | ||
- `unoptimized` - When true, the source image will be served as-is instead of resizing and changing quality. | ||
- `unsized` - When true, the `width` and `height` requirement can by bypassed. Should _not_ be used with above-the-fold images. Should _not_ be used with `priority`. | ||
|
||
All other properties on the `<Image>` component will be passed to the underlying `<img>` element. |
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 |
---|---|---|
@@ -0,0 +1,120 @@ | ||
--- | ||
description: Next.js supports built-in image optimization, as well as third party loaders for Imgix, Cloudinary, and more! Learn more here. | ||
--- | ||
|
||
# Image Component and Image Optimization | ||
|
||
<details open> | ||
<summary><b>Examples</b></summary> | ||
<ul> | ||
<li><a href="https://github.com/vercel/next.js/tree/canary/examples/image-component">Image Component</a></li> | ||
</ul> | ||
</details> | ||
|
||
Since version **10.0.0** Next.js has a built-in Image Component and Automatic Image Optimization. | ||
|
||
The Next.js Image Component (`next/image`) is an extension of the HTML `<img>` element, evolved for the modern web. | ||
|
||
The Automatic Image Optimization allows for resizing, optimizing, and serving images in modern formats like [WebP](https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Image_types). This avoids shipping large images to devices with a smaller viewport. | ||
|
||
## Image Component | ||
|
||
To add an image to your application, import the [`next/image`](/docs/api-reference/next/image.md) component: | ||
|
||
```jsx | ||
import Image from 'next/image' | ||
|
||
function Home() { | ||
return ( | ||
<> | ||
<h1>My Homepage</h1> | ||
<Image | ||
src="/me.png" | ||
alt="Picture of the author" | ||
width={500} | ||
height={500} | ||
/> | ||
<p>Welcome to my homepage!</p> | ||
</> | ||
) | ||
} | ||
|
||
export default Home | ||
``` | ||
|
||
- `width` and `height` are required to prevent [Cumulative Layout Shift](https://web.dev/cls/), a [Core Web Vital](https://web.dev/vitals/) that Google is going to [use in their search ranking](https://webmasters.googleblog.com/2020/05/evaluating-page-experience.html) | ||
- `width` and `height` are automatically responsive, unlike the HTML `<img>` element | ||
- See [`next/image`](/docs/api-reference/next/image.md) for list of available props. | ||
|
||
## Configuration | ||
|
||
You can configure Image Optimization by using the `images` property in `next.config.js`. | ||
|
||
### Device Sizes | ||
|
||
You can specify a list of device width breakpoints using the `deviceSizes` property. Since images maintain their aspect ratio using the `width` and `height` attributes of the source image, there is no need to specify height in `next.config.js` – only the width. These values will be used by the browser to determine which size image should load. | ||
|
||
```js | ||
module.exports = { | ||
images: { | ||
deviceSizes: [320, 420, 768, 1024, 1200], | ||
}, | ||
} | ||
``` | ||
|
||
### Image Sizes | ||
|
||
You can specify a list of exact image widths using the `imageSizes` property. These widths should be different than the widths defined in `deviceSizes`. The purpose is for images that don't scale with the browser window, such as icons, badges, or profile images. If the `width` property of a [`next/image`](/docs/api-reference/next/image.md) component matches a value in `imageSizes`, the image will be rendered at that exact width. | ||
|
||
```js | ||
module.exports = { | ||
images: { | ||
imageSizes: [16, 32, 64], | ||
}, | ||
} | ||
``` | ||
|
||
### Domains | ||
|
||
To enable Image Optimization for images hosted on an external website, use an absolute url for the Image `src` and specify which | ||
`domains` are allowed to be optimized. This is needed to ensure that external urls can't be abused. | ||
|
||
```js | ||
module.exports = { | ||
images: { | ||
domains: ['example.com'], | ||
}, | ||
} | ||
``` | ||
|
||
### Loader | ||
|
||
If you want to use a cloud image provider to optimize images instead of using the Next.js' built-in image optimization, you can configure the loader and path prefix. This allows you to use relative urls for the Image `src` and automatically generate the correct absolute url for your provider. | ||
|
||
```js | ||
module.exports = { | ||
images: { | ||
loader: 'imgix', | ||
path: 'https://example.com/myaccount/', | ||
}, | ||
} | ||
``` | ||
|
||
The following Image Optimization cloud providers are supported: | ||
|
||
- When using `next start` or a custom server image optimization works automatically. | ||
- [Vercel](https://vercel.com): Works automatically when you deploy on Vercel | ||
- [Imgix](https://www.imgix.com): `loader: 'imgix'` | ||
- [Cloudinary](https://cloudinary.com): `loader: 'cloudinary'` | ||
- [Akamai](https://www.akamai.com): `loader: 'akamai'` | ||
|
||
## Related | ||
|
||
For more information on what to do next, we recommend the following sections: | ||
|
||
<div class="card"> | ||
<a href="/docs/api-reference/next/image.md"> | ||
<b>next/image</b> | ||
<small>See all available properties for the Image component</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
# vercel | ||
.vercel |
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,23 @@ | ||
# Internationalized Routing | ||
|
||
This example shows how to create internationalized pages using Next.js and the i18n routing feature. It shows a normal page, a non-dynamic `getStaticProps` page, a dynamic `getStaticProps` page, and a `getServerSideProps` page. | ||
|
||
For further documentation on this feature see the documentation [here](https://nextjs.org/docs/advanced-features/i18n-routing) | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com): | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/import/project?template=https://github.com/vercel/next.js/tree/canary/examples/amp) | ||
|
||
## How to use | ||
|
||
Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example: | ||
|
||
```bash | ||
npx create-next-app --example i18n-routing i18n-app | ||
# or | ||
yarn create next-app --example i18n-routing i18n-app | ||
``` | ||
|
||
Deploy it to the cloud with [Vercel](https://vercel.com/import?filter=next.js&utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)). |
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,6 @@ | ||
module.exports = { | ||
i18n: { | ||
locales: ['en', 'fr', 'nl'], | ||
defaultLocale: 'en', | ||
}, | ||
} |
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,15 @@ | ||
{ | ||
"name": "i18n-routing", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"next": "latest", | ||
"react": "^16.7.0", | ||
"react-dom": "^16.7.0" | ||
}, | ||
"license": "MIT" | ||
} |
Oops, something went wrong.