From 198bdf9e6eeafcfd04e105c380fcceabed54ddbe Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 14 Jan 2025 13:16:20 +0100 Subject: [PATCH] doc(cloudflare): updates - unify npm script names with the c3 template - add cf-typegen script --- pages/cloudflare/caching.mdx | 15 +++++++++++---- pages/cloudflare/get-started.mdx | 8 +++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/pages/cloudflare/caching.mdx b/pages/cloudflare/caching.mdx index 50e02f3..93411f3 100644 --- a/pages/cloudflare/caching.mdx +++ b/pages/cloudflare/caching.mdx @@ -33,8 +33,15 @@ npx wrangler@latest kv namespace create The binding name used in your app's worker is `NEXT_CACHE_WORKERS_KV`. -``` -[[kv_namespaces]] -binding = "NEXT_CACHE_WORKERS_KV" -id = "" +```jsonc +// wrangler.json +{ + // ... + "kv_namespaces": [ + { + "binding": "NEXT_CACHE_WORKERS_KV", + "id": "" + } + ] +} ``` diff --git a/pages/cloudflare/get-started.mdx b/pages/cloudflare/get-started.mdx index 8817ae9..ccb2907 100644 --- a/pages/cloudflare/get-started.mdx +++ b/pages/cloudflare/get-started.mdx @@ -129,14 +129,16 @@ Add the following to the scripts field of your `package.json` file: ```json "build:worker": "opennextjs-cloudflare", "dev:worker": "wrangler dev --port 8771", -"preview:worker": "npm run build:worker && npm run dev:worker", -"deploy:worker": "npm run build:worker && wrangler deploy" +"preview": "npm run build:worker && npm run dev:worker", +"deploy": "npm run build:worker && wrangler deploy", +"cf-typegen": "wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts", ``` - `npm run build:worker`: Runs the [@opennextjs/cloudflare](https://www.npmjs.com/package/@opennextjs/cloudflare) adapter. This first builds your app by running the `build` script in your `package.json` (Next.js apps use `next build` by default), and then transforms the build output to a format that you can run locally using [Wrangler](https://developers.cloudflare.com/workers/wrangler/), and deploy to Cloudflare. The build command used by OpenNext can be overridden with the `buildCommand` option in your OpenNext config. - `npm run dev:worker`: Takes the output generated by `build:worker` and runs it locally in [workerd](https://github.com/cloudflare/workerd), the open-source Workers Runtime, allowing you to run the app locally in the same environment that it will run in production. If you instead run `next dev`, your app will run in Node.js, which is a different JavaScript runtime from the Workers runtime, with differences in behavior and APIs. -- `npm run preview:worker`: Runs `build:worker` and then `dev:worker`, allowing you to quickly preview your app running locally in the Workers runtime, via a single command. +- `npm run preview`: Runs `build:worker` and then `dev:worker`, allowing you to quickly preview your app running locally in the Workers runtime, via a single command. - `npm run deploy`: Builds your app, and then deploys it to Cloudflare +- `cf-typegen`: Generates a `cloudflare-env.d.ts` file at the root of your project containing [the types for the `env`](https://developers.cloudflare.com/workers/wrangler/commands/#types). ##### 7. Add caching with Workers KV