Unverified Commit 2318b5e2 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

docs: Remove AMP docs (#84357)

Stacked on https://github.com/vercel/next.js/pull/84312

Removes the AMP docs, which is no longer supported.
parent 43b8e3d6
......@@ -531,6 +531,8 @@ The component will have a camel-cased name based on the name of the file, and it
### 8
> **Note**: Built-in AMP support and this codemod have been removed in Next.js 16.
#### Transform AMP HOC into page config
##### `withamp-to-config`
......
......@@ -160,8 +160,6 @@ Some features are not yet implemented or not planned:
- `@import` in CSS Modules importing `.css` as a CSS Module. In webpack this would treat the `.css` file as a CSS Module, with Turbopack the `.css` file will always be global. This means that if you want to use `@import` in a CSS Module, you need to change the `.css` file to a `.module.css` file.
- **`webpack()` configuration** in `next.config.js`
Turbopack replaces webpack, so `webpack()` configs are not recognized. Use the [`turbopack` config](/docs/app/api-reference/config/next-config-js/turbopack) instead.
- **AMP**
Not planned for Turbopack support in Next.js.
- **Yarn PnP**
Not planned for Turbopack support in Next.js.
- **`experimental.urlImports`**
......
---
title: How to create AMP pages in Next.js
nav_title: AMP
description: With minimal config, and without leaving React, you can start adding AMP and improve the performance and speed of your pages.
---
<details>
<summary>Examples</summary>
- [AMP](https://github.com/vercel/next.js/tree/canary/examples/amp)
</details>
> **Warning**: Built-in AMP support will be removed in Next.js 16.
With Next.js you can turn any React page into an AMP page, with minimal config, and without leaving React.
You can read more about AMP in the official [amp.dev](https://amp.dev/) site.
## Enabling AMP
To enable AMP support for a page, and to learn more about the different AMP configs, read the [API documentation for `next/amp`](/docs/pages/guides/amp).
## Caveats
- Only CSS-in-JS is supported. [CSS Modules](/docs/app/getting-started/css) aren't supported by AMP pages at the moment. You can [contribute CSS Modules support to Next.js](https://github.com/vercel/next.js/issues/10549).
## Adding AMP Components
The AMP community provides [many components](https://amp.dev/documentation/components/) to make AMP pages more interactive. Next.js will automatically import all components used on a page and there is no need to manually import AMP component scripts:
```jsx
export const config = { amp: true }
function MyAmpPage() {
const date = new Date()
return (
<div>
<p>Some time: {date.toJSON()}</p>
<amp-timeago
width="0"
height="15"
datetime={date.toJSON()}
layout="responsive"
>
.
</amp-timeago>
</div>
)
}
export default MyAmpPage
```
The above example uses the [`amp-timeago`](https://amp.dev/documentation/components/amp-timeago/?format=websites) component.
By default, the latest version of a component is always imported. If you want to customize the version, you can use `next/head`, as in the following example:
```jsx
import Head from 'next/head'
export const config = { amp: true }
function MyAmpPage() {
const date = new Date()
return (
<div>
<Head>
<script
async
key="amp-timeago"
custom-element="amp-timeago"
src="https://cdn.ampproject.org/v0/amp-timeago-0.1.js"
/>
</Head>
<p>Some time: {date.toJSON()}</p>
<amp-timeago
width="0"
height="15"
datetime={date.toJSON()}
layout="responsive"
>
.
</amp-timeago>
</div>
)
}
export default MyAmpPage
```
## AMP Validation
AMP pages are automatically validated with [amphtml-validator](https://www.npmjs.com/package/amphtml-validator) during development. Errors and warnings will appear in the terminal where you started Next.js.
Pages are also validated during [Static HTML export](/docs/pages/guides/static-exports) and any warnings / errors will be printed to the terminal. Any AMP errors will cause the export to exit with status code `1` because the export is not valid AMP.
### Custom Validators
You can set up custom AMP validator in `next.config.js` as shown below:
```js
module.exports = {
amp: {
validator: './custom_validator.js',
},
}
```
### Skip AMP Validation
To turn off AMP validation add the following code to `next.config.js`
```js
experimental: {
amp: {
skipValidation: true
}
}
```
### AMP in Static HTML Export
When using [Static HTML export](/docs/pages/guides/static-exports) statically prerender pages, Next.js will detect if the page supports AMP and change the exporting behavior based on that.
For example, the hybrid AMP page `pages/about.js` would output:
- `out/about.html` - HTML page with client-side React runtime
- `out/about.amp.html` - AMP page
And if `pages/about.js` is an AMP-only page, then it would output:
- `out/about.html` - Optimized AMP page
Next.js will automatically insert a link to the AMP version of your page in the HTML version, so you don't have to, like so:
```jsx
<link rel="amphtml" href="/about.amp.html" />
```
And the AMP version of your page will include a link to the HTML page:
```jsx
<link rel="canonical" href="/about" />
```
When [`trailingSlash`](/docs/pages/api-reference/config/next-config-js/trailingSlash) is enabled the exported pages for `pages/about.js` would be:
- `out/about/index.html` - HTML page
- `out/about.amp/index.html` - AMP page
## TypeScript
AMP currently doesn't have built-in types for TypeScript, but it's in their roadmap ([#13791](https://github.com/ampproject/amphtml/issues/13791)).
As a workaround you can manually create a file called `amp.d.ts` inside your project and add these [custom types](https://stackoverflow.com/a/50601125).
---
title: useAmp
description: Enable AMP in a page, and control the way Next.js adds AMP to the page with the AMP config.
---
<details>
<summary>Examples</summary>
- [AMP](https://github.com/vercel/next.js/tree/canary/examples/amp)
</details>
> **Warning**: Built-in AMP support will be removed in Next.js 16.
To enable AMP, add the following config to your page:
```jsx filename="pages/index.js"
export const config = { amp: true }
```
The `amp` config accepts the following values:
- `true` - The page will be AMP-only
- `'hybrid'` - The page will have two versions, one with AMP and another one with HTML
To learn more about the `amp` config, read the sections below.
## AMP First Page
Take a look at the following example:
```jsx filename="pages/about.js"
export const config = { amp: true }
function About(props) {
return <h3>My AMP About Page!</h3>
}
export default About
```
The page above is an AMP-only page, which means:
- The page has no Next.js or React client-side runtime
- The page is automatically optimized with [AMP Optimizer](https://github.com/ampproject/amp-toolbox/tree/master/packages/optimizer), an optimizer that applies the same transformations as AMP caches (improves performance by up to 42%)
- The page has a user-accessible (optimized) version of the page and a search-engine indexable (unoptimized) version of the page
## Hybrid AMP Page
Take a look at the following example:
```jsx filename="pages/about.js"
import { useAmp } from 'next/amp'
export const config = { amp: 'hybrid' }
function About(props) {
const isAmp = useAmp()
return (
<div>
<h3>My AMP About Page!</h3>
{isAmp ? (
<amp-img
width="300"
height="300"
src="/my-img.jpg"
alt="a cool image"
layout="responsive"
/>
) : (
<img width="300" height="300" src="/my-img.jpg" alt="a cool image" />
)}
</div>
)
}
export default About
```
The page above is a hybrid AMP page, which means:
- The page is rendered as traditional HTML (default) and AMP HTML (by adding `?amp=1` to the URL)
- The AMP version of the page only has valid optimizations applied with AMP Optimizer so that it is indexable by search-engines
The page uses `useAmp` to differentiate between modes, it's a [React Hook](https://react.dev/reference/react) that returns `true` if the page is using AMP, and `false` otherwise.
---
title: Resolving "AMP Bind JSX Error" in Next.js
description: This document explains the "AMP Bind JSX Error" in Next.js and provides a valid solution to resolve it.
---
## Why This Error Occurred
The "AMP Bind JSX Error" arises when you use the `[prop]='something'` syntax somewhere in your code.
JSX is a syntax extension for JavaScript used by React (and by extension, Next.js). JSX does not support the usage of this particular syntax, hence the error.
## Possible Ways to Fix It
To fix this issue, instead of using `[prop]='something'`, you can use `data-amp-bind-prop='something'`. This is a valid alternative in Accelerated Mobile Pages (AMP) that works well with JSX.
## Useful Links
- [AMP HTML Specification](https://www.ampproject.org/docs/fundamentals/spec) - Understand the underlying standards and rules for creating AMP pages.
- [Possible future syntax](https://github.com/ampproject/amphtml/issues/21600) - Check out the discussions on potential syntax changes that may be applicable in the future.
---
title: Troubleshooting "AMP Export Validation" Error in Next.js
description: This document provides insights on the "AMP Export Validation" error in Next.js and how to address it.
---
## Why This Error Occurred
The "AMP Export Validation" error typically occurs during the export process when the AMP pages are validated using the [amphtml-validator](https://www.npmjs.com/package/amphtml-validator). If the validator returns any errors, the export process will fail.
AMP validation errors are crucial as they can prevent your pages from being indexed by AMP Caches. AMP Caches are systems that store and serve valid AMP documents to ensure faster delivery of AMP pages to users.
## Possible Ways to Fix It
To resolve this issue, carefully review the error messages provided by the validator. These messages usually provide detailed insights into the problem and how to fix it. Following the links associated with these error messages can also guide you to more information about the particular error and its solution.
## Useful Links
- [AMP HTML Specification](https://www.ampproject.org/docs/fundamentals/spec) - Get more details about AMP standards and conventions to ensure your pages are compliant.
---
title: Conflicting AMP Tag
---
## Why This Error Occurred
In AMP mode Next.js adds certain necessary tags automatically to comply with the AMP standard. You added a tag using `next/head` that conflicts with one of these automatically added tags.
## Possible Ways to Fix It
Remove the tag mentioned in the error message from any `<Head></Head>` elements
......@@ -41,36 +41,6 @@ export const config = {}
<tr>
<td>
```js
export const config = {}
// `config.amp` is defined after `config` is exported
config.amp = true
// `config.amp` contains a dynamic expression
export const config = {
amp: 1 + 1 > 2,
}
```
</td>
<td>
```js
export const config = {
amp: true,
}
export const config = {
amp: false,
}
```
</td>
</tr>
<tr>
<td>
```js
// `config.runtime` contains a dynamic expression
export const config = {
......@@ -116,6 +86,5 @@ export const config = {}
## Useful Links
- [Enabling AMP Support](/docs/pages/guides/amp)
- [API Routes Request Helpers](/docs/pages/building-your-application/routing/api-routes)
- [Edge Runtime](/docs/app/api-reference/edge)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment