Unverified Commit acf5e845 authored by Steven's avatar Steven Committed by GitHub

chore(docs): update static exports documentation with missing info (#53592)

- Related to https://github.com/vercel/next.js/issues/48022
parent 1df2686b
...@@ -27,8 +27,13 @@ To enable a static export, change the output mode inside `next.config.js`: ...@@ -27,8 +27,13 @@ To enable a static export, change the output mode inside `next.config.js`:
*/ */
const nextConfig = { const nextConfig = {
output: 'export', output: 'export',
// Optional: Add a trailing slash to all paths `/about` -> `/about/`
// Optional: Change links `/me` -> `/me/` and emit `/me.html` -> `/me/index.html`
// trailingSlash: true, // trailingSlash: true,
// Optional: Prevent automatic `/me` -> `/me/`, instead preserve `href`
// skipTrailingSlashRedirect: true,
// Optional: Change the output directory `out` -> `dist` // Optional: Change the output directory `out` -> `dist`
// distDir: 'dist', // distDir: 'dist',
} }
...@@ -175,7 +180,7 @@ const nextConfig = { ...@@ -175,7 +180,7 @@ const nextConfig = {
output: 'export', output: 'export',
images: { images: {
loader: 'custom', loader: 'custom',
loaderFile: './app/image.ts', loaderFile: './my-loader.ts',
}, },
} }
...@@ -184,7 +189,7 @@ module.exports = nextConfig ...@@ -184,7 +189,7 @@ module.exports = nextConfig
This custom loader will define how to fetch images from a remote source. For example, the following loader will construct the URL for Cloudinary: This custom loader will define how to fetch images from a remote source. For example, the following loader will construct the URL for Cloudinary:
```ts filename="app/image.ts" switcher ```ts filename="my-loader.ts" switcher
export default function cloudinaryLoader({ export default function cloudinaryLoader({
src, src,
width, width,
...@@ -201,7 +206,7 @@ export default function cloudinaryLoader({ ...@@ -201,7 +206,7 @@ export default function cloudinaryLoader({
} }
``` ```
```js filename="app/image.js" switcher ```js filename="my-loader.js" switcher
export default function cloudinaryLoader({ src, width, quality }) { export default function cloudinaryLoader({ src, width, quality }) {
const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`] const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`]
return `https://res.cloudinary.com/demo/image/upload/${params.join( return `https://res.cloudinary.com/demo/image/upload/${params.join(
...@@ -277,31 +282,32 @@ export default function ClientComponent() { ...@@ -277,31 +282,32 @@ export default function ClientComponent() {
## Unsupported Features ## Unsupported Features
Features that require a Node.js server, or dynamic logic that cannot be computed during the build process, are **not** supported:
<AppOnly> <AppOnly>
After enabling the static export `output` mode, all routes inside `app` are opted-into the following [Route Segment Config](/docs/app/api-reference/file-conventions/route-segment-config): - [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes) with `dynamicParams: true`
- [Dynamic Routes](/docs/app/building-your-application/routing/dynamic-routes) without `generateStaticParams()`
- [Route Handlers](/app/building-your-application/routing/route-handlers) that rely on Request
- [Cookies](/docs/app/api-reference/functions/cookies)
- [Rewrites](/docs/app/api-reference/next-config-js/rewrites)
- [Redirects](/docs/app/api-reference/next-config-js/redirects)
- [Headers](/docs/app/api-reference/next-config-js/headers)
- [Middleware](/docs/app/building-your-application/routing/middleware)
- [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
- [Image Optimization](/docs/app/building-your-application/optimizing/images) with the default `loader`
- [Draft Mode](/docs/app/building-your-application/configuring/draft-mode)
Attempting to use any of these features with `next dev` will result in an error, similar to setting the [`dynamic`](/docs/app/api-reference/file-conventions/route-segment-config#dynamic) option to `error` in the root layout.
```jsx ```jsx
export const dynamic = 'error' export const dynamic = 'error'
``` ```
With this configuration, your application **will produce an error** if you try to use server functions like [`headers`](/docs/app/api-reference/functions/headers) or [`cookies`](/docs/app/api-reference/functions/cookies), since there is no runtime server. This ensures local development matches the same behavior as a static export. If you need to use server functions, you cannot use a static export.
The following additional dynamic features are not supported with a static export:
- [Dynamic Routes](https://nextjs.org/docs/app/building-your-application/routing/dynamic-routes) without `generateStaticParams()`
- `rewrites` in `next.config.js`
- `redirects` in `next.config.js`
- `headers` in `next.config.js`
- Middleware
- [Incremental Static Regeneration](/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating)
</AppOnly> </AppOnly>
<PagesOnly> <PagesOnly>
Features that require a Node.js server, or dynamic logic that cannot be computed during the build process, are not supported:
- [Internationalized Routing](/docs/pages/building-your-application/routing/internationalization) - [Internationalized Routing](/docs/pages/building-your-application/routing/internationalization)
- [API Routes](/docs/pages/building-your-application/routing/api-routes) - [API Routes](/docs/pages/building-your-application/routing/api-routes)
- [Rewrites](/docs/pages/api-reference/next-config-js/rewrites) - [Rewrites](/docs/pages/api-reference/next-config-js/rewrites)
...@@ -309,10 +315,11 @@ Features that require a Node.js server, or dynamic logic that cannot be computed ...@@ -309,10 +315,11 @@ Features that require a Node.js server, or dynamic logic that cannot be computed
- [Headers](/docs/pages/api-reference/next-config-js/headers) - [Headers](/docs/pages/api-reference/next-config-js/headers)
- [Middleware](/docs/pages/building-your-application/routing/middleware) - [Middleware](/docs/pages/building-your-application/routing/middleware)
- [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration) - [Incremental Static Regeneration](/docs/pages/building-your-application/data-fetching/incremental-static-regeneration)
- [Image Optimization](/docs/pages/building-your-application/optimizing/images) with the default `loader`
- [Draft Mode](/docs/pages/building-your-application/configuring/draft-mode)
- [`getStaticPaths` with `fallback: true`](/docs/pages/api-reference/functions/get-static-paths#fallback-true) - [`getStaticPaths` with `fallback: true`](/docs/pages/api-reference/functions/get-static-paths#fallback-true)
- [`getStaticPaths` with `fallback: 'blocking'`](/docs/pages/api-reference/functions/get-static-paths#fallback-blocking) - [`getStaticPaths` with `fallback: 'blocking'`](/docs/pages/api-reference/functions/get-static-paths#fallback-blocking)
- [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props) - [`getServerSideProps`](/docs/pages/building-your-application/data-fetching/get-server-side-props)
- [Image Optimization](/docs/pages/building-your-application/optimizing/images) (default loader)
</PagesOnly> </PagesOnly>
...@@ -345,6 +352,8 @@ server { ...@@ -345,6 +352,8 @@ server {
try_files $uri $uri.html $uri/ =404; try_files $uri $uri.html $uri/ =404;
} }
# This is necessary when `trailingSlash: false`.
# You can omit this when `trailingSlash: true`.
location /blog/ { location /blog/ {
rewrite ^/blog/(.*)$ /blog/$1.html break; rewrite ^/blog/(.*)$ /blog/$1.html break;
} }
......
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