Skip to content

Commit 72579cb

Browse files
Add documentation for new migrate Cloudflare CLI command (#205)
1 parent 2fd894b commit 72579cb

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

pages/cloudflare/cli.mdx

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The Cloudflare adapter provides a `opennextjs-cloudflare` CLI to develop, build,
88

99
`opennextjs-cloudflare` support multiple commands, invoked via `opennextjs-cloudflare <command>`.
1010

11-
The currently supported commands are `build`, `populateCache`, `preview`, `deploy`, and `upload`.
11+
The currently supported commands are `build`, `populateCache`, `preview`, `deploy`, `upload`, and `migrate`.
1212

1313
You can list the commands by invoking `pnpm opennextjs-cloudflare` and get help with a given command by invoking `pnpm opennextjs-cloudflare <command> --help`.
1414

@@ -47,3 +47,30 @@ It starts by populating the remote cache and then deploys your application to Cl
4747
### `upload` command
4848

4949
It starts by populating the remote cache and then uploads a version of your application to Cloudflare (via `wrangler upload`). Note that the application will not automatically be served on uploads. See [Gradual deployments](https://developers.cloudflare.com/workers/configuration/versions-and-deployments/gradual-deployments/) to learn more about how to serve an uploaded version.
50+
51+
### `migrate` command
52+
53+
Converts a standard Next.js project into an OpenNext-compatible one. This command automates the setup steps described in the [Get Started guide](/cloudflare/get-started#existing-nextjs-apps), including:
54+
55+
- Installing required dependencies (`@opennextjs/cloudflare` and `wrangler`)
56+
- Creating a `wrangler.jsonc` configuration file
57+
- Creating an `open-next.config.ts` file
58+
- Adding a `.dev.vars` file
59+
- Updating the `package.json` scripts
60+
- Adding static asset caching headers (`public/_headers`)
61+
- Adding `.open-next` to `.gitignore`
62+
- Setting up local development with `initOpenNextCloudflareForDev()` in your Next.js config
63+
64+
Additionally, the command creates an R2 bucket and configures it for caching.
65+
66+
<Callout type="info">
67+
The R2 bucket for caching is only created if R2 is enabled on your Cloudflare account. If R2 is not enabled,
68+
no caching setup is performed by the migrate command. See the [Caching docs](/cloudflare/caching) for
69+
information on manually configuring caching.
70+
</Callout>
71+
72+
Run the command in your existing Next.js project:
73+
74+
```sh
75+
npx @opennextjs/cloudflare migrate
76+
```

pages/cloudflare/get-started.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ npm create cloudflare@latest -- my-next-app --framework=next --platform=workers
1212

1313
#### Existing Next.js apps
1414

15+
The easiest way to convert an existing Next.js app is to use the `migrate` command:
16+
17+
```sh
18+
npx @opennextjs/cloudflare migrate
19+
```
20+
21+
This command automates all the setup steps below. If R2 is enabled on your account, it also creates an R2 bucket for caching. See the [CLI documentation](/cloudflare/cli#migrate-command) for more details.
22+
23+
Alternatively, you can follow the manual steps below.
24+
1525
##### 1. Install @opennextjs/cloudflare
1626

1727
First, install [@opennextjs/cloudflare](https://www.npmjs.com/package/@opennextjs/cloudflare):

0 commit comments

Comments
 (0)