You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Install the [Wrangler CLI](https://developers.cloudflare.com/workers/wrangler/) as a devDependency:
27
27
28
-
```npm
28
+
```sh
29
29
npm install --save-dev wrangler@latest
30
30
```
31
31
@@ -157,26 +157,25 @@ This includes:
157
157
You can continue to run `next dev` when developing locally.
158
158
159
159
Modify your Next.js configuration file to import and call the `initOpenNextCloudflareForDev` utility
160
-
from the `@opennextjs/cloudflare` package. This makes sure that the Next.js dev server can optimally integrate with the open-next
161
-
cloudflare adapter and it is necessary for using bindings during local development.
160
+
from the `@opennextjs/cloudflare` package. This makes sure that the Next.js dev server can optimally integrate with the open-next cloudflare adapter and it is necessary for using bindings during local development.
162
161
163
162
This is an example of a Next.js configuration file calling the utility:
After having added the `initOpenNextCloudflareForDev()` call in your Next.js configuration file, you will be able, during local
179
-
development, to access in any of your server code, local versions of Cloudflare bindings as indicated in the [bindings documentation](./bindings).
178
+
After having added the `initOpenNextCloudflareForDev()` call in your Next.js configuration file, you will be able, during local development, to access in any of your server code, local versions of Cloudflare bindings as indicated in the [bindings documentation](./bindings).
180
179
181
180
In step 3, we also added the `npm run preview`, which allows you to quickly preview your app running locally in the Workers runtime,
182
181
rather than in Node.js. This allows you to test changes in the same runtime as your app will run in when deployed to Cloudflare.
The primary purpose of `@opennextjs/cloudflare` is to take a Next.js application, built with standard Next.js tooling, and convert it into a format compatible with Cloudflare Workers.
4
+
5
+
This code transformation process takes some time, making the adapter less than ideal for active application development, where a very fast feedback loop and other quality-of-life features, such as Hot Module Replacement (HMR), are crucial. Fortunately, Vercel already provides excellent tooling for this workflow, which Next.js developers are likely already familiar with.
6
+
7
+
We recommend that developers continue using the tools they are already comfortable with for local development and then use `@opennextjs/cloudflare` when they are ready to deploy their applications to the Cloudflare platform.
8
+
9
+
Let's explore, in more detail, the application development workflow we recommend for the best developer experience.
10
+
11
+
### Create a new application based on a template
12
+
13
+
To create a new Next.js app, pre-configured to run on Cloudflare using `@opennextjs/cloudflare`, run:
We believe that the best development workflow uses the `next dev` command provided by Next.js.
22
+
23
+
To access Cloudflare resources using the `getCloudflareContext` API while running `next dev`, you will need to update the Next.js configuration to call `initOpenNextCloudflareForDev`, as shown in the following example:
After you've finished iterating on your Next.js application with `next dev`, you can convert it to a Cloudflare Worker by running the `opennextjs-cloudflare` command. This will generate the Worker code in the `.open-next` directory.
42
+
43
+
You can then preview the app locally in the Cloudflare Workers runtime or deploy it to the Cloudflare network.
44
+
45
+
To preview your worker locally, run the `wrangler dev` command. This creates a local server that runs your worker in the Cloudflare Workers runtime. Testing your worker is important to ensure that it has been properly built and is working as expected.
46
+
47
+
Once you've tested your worker, You can run `wrangler deploy`, and in a matter of seconds, your masterpiece will be available to all your users around the world.
0 commit comments