|
1 |
| -# Next.js builder for Cloudflare |
| 1 | +# OpenNext for Cloudflare |
2 | 2 |
|
3 |
| -How to update a Next.js application to run on Cloudflare. |
| 3 | +Deploy Next.js apps to Cloudflare! |
4 | 4 |
|
5 |
| -## Configure your app |
| 5 | +OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare. |
6 | 6 |
|
7 |
| -- add the following `devDependencies` to the `package.json`: |
| 7 | +## Getting started |
8 | 8 |
|
9 |
| - ```bash |
10 |
| - pnpm add -D wrangler@latest @opennextjs/cloudflare |
11 |
| - ``` |
| 9 | +You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/create-next-app) to start a new application or take an existing Next.js application and deploy it to Cloudflare using the following few steps: |
12 | 10 |
|
13 |
| -## Serve your app |
| 11 | +## Configure your app |
14 | 12 |
|
15 |
| -- build the app and adapt it for Cloudflare |
| 13 | +- add the following `devDependencies` to the `package.json`: |
16 | 14 |
|
17 | 15 | ```bash
|
18 |
| - pnpx cloudflare |
| 16 | + pnpm add -D wrangler@latest @opennextjs/cloudflare |
19 | 17 | ```
|
20 | 18 |
|
21 | 19 | - add a `wrangler.toml` at the root of your project
|
22 | 20 |
|
23 | 21 | ```toml
|
24 | 22 | #:schema node_modules/wrangler/config-schema.json
|
25 |
| - name = "<app-name>" |
| 23 | + name = "<your-app-name>" |
26 | 24 | main = ".worker-next/index.mjs"
|
27 | 25 |
|
28 |
| - compatibility_date = "2024-08-29" |
29 |
| - compatibility_flags = ["nodejs_compat_v2"] |
| 26 | + compatibility_date = "2024-09-23" |
| 27 | + compatibility_flags = ["nodejs_compat"] |
30 | 28 |
|
31 | 29 | # Use the new Workers + Assets to host the static frontend files
|
32 | 30 | experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" }
|
33 | 31 | ```
|
34 | 32 |
|
| 33 | +## Local development |
| 34 | + |
| 35 | +- you can use the regular `next` CLI to start the Next.js dev server: |
| 36 | + |
| 37 | +## Local preview |
| 38 | + |
| 39 | +Run the following commands to preview the production build of your application locally: |
| 40 | + |
| 41 | +- build the app and adapt it for Cloudflare |
| 42 | + |
| 43 | + ```bash |
| 44 | + pnpx cloudflare |
| 45 | + ``` |
| 46 | + |
35 | 47 | - Preview the app in Wrangler
|
36 | 48 |
|
37 | 49 | ```bash
|
38 | 50 | pnpm wrangler dev
|
39 | 51 | ```
|
| 52 | + |
| 53 | +## Deploy your app |
| 54 | + |
| 55 | +Deploy your application to production with the following: |
| 56 | + |
| 57 | +- build the app and adapt it for Cloudflare |
| 58 | + |
| 59 | + ```bash |
| 60 | + pnpx cloudflare |
| 61 | + ``` |
| 62 | + |
| 63 | + ```bash |
| 64 | + pnpm wrangler deploy |
| 65 | + ``` |
0 commit comments