From 938ecb954a62451cf03eb54fab4bcd46aed0627c Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 24 Sep 2024 23:55:06 -0500 Subject: [PATCH 1/2] docs: improve repo and npm package README.md files --- README.md | 17 ++++++++---- packages/cloudflare/README.md | 52 ++++++++++++++++++++++++++--------- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index ad6bcdf0..71653db8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,23 @@ -# [POC] Build Next.js app for cf workers +# Deploy Next.js apps to Cloudflare! -This monorepo includes a package for adapting a Next.js application built via `next build` (in standalone mode) to run in the Cloudflare workerd runtime. +OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare. -> [!NOTE] -> The code here is built based on the amazing work done by @mhart in +This monorepo includes a package for adapting a Next.js application built via `next build` (in standalone mode) to run in the Cloudflare workerd runtime using the [Workers Node.js compatibility layer](https://developers.cloudflare.com/workers/runtime-apis/nodejs/). -## The repository +## Get started + +Follow instructions at [`@opennextjs/cloudflare`](https://www.npmjs.com/package/@opennextjs/cloudflare). + +## Contributing + +### The repository The repository contains two directories: - `packages` containing a cloudflare package that can be used to build Cloudflare workers compatible output from Next.js applications - `examples` containing Next.js applications that use the above mentioned cloudflare. -## How to try out/develop in the repository +### How to try out/develop in the repository Install the dependencies: diff --git a/packages/cloudflare/README.md b/packages/cloudflare/README.md index 599d0322..9b10592e 100644 --- a/packages/cloudflare/README.md +++ b/packages/cloudflare/README.md @@ -1,39 +1,65 @@ -# Next.js builder for Cloudflare +# OpenNext for Cloudflare -How to update a Next.js application to run on Cloudflare. +Deploy Next.js apps to Cloudflare! -## Configure your app +OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare. -- add the following `devDependencies` to the `package.json`: +## Getting started - ```bash - pnpm add -D wrangler@latest @opennextjs/cloudflare - ``` +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: -## Serve your app +## Configure your app -- build the app and adapt it for Cloudflare +- add the following `devDependencies` to the `package.json`: ```bash - pnpx cloudflare + pnpm add -D wrangler@latest @opennextjs/cloudflare ``` - add a `wrangler.toml` at the root of your project ```toml #:schema node_modules/wrangler/config-schema.json - name = "" + name = "" main = ".worker-next/index.mjs" - compatibility_date = "2024-08-29" - compatibility_flags = ["nodejs_compat_v2"] + compatibility_date = "2024-09-23" + compatibility_flags = ["nodejs_compat"] # Use the new Workers + Assets to host the static frontend files experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" } ``` +## Local development + +- you can use the regular `next` CLI to start the Next.js dev server: + + +## Local preview + +Run the following commands to preview the production build of your application locally: + +- build the app and adapt it for Cloudflare + + ```bash + pnpx cloudflare + ``` - Preview the app in Wrangler ```bash pnpm wrangler dev ``` + +## Deploy your app + +Deploy your application to production with the following: + +- build the app and adapt it for Cloudflare + + ```bash + pnpx cloudflare + ``` + +```bash +pnpm wrangler deploy +``` From 9bca0bf8b97e10384a31063c49ab2292224db3bd Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Wed, 25 Sep 2024 10:32:34 +0200 Subject: [PATCH 2/2] fixup! --- README.md | 2 +- packages/cloudflare/README.md | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 71653db8..64a48118 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Deploy Next.js apps to Cloudflare! +# Deploy Next.js apps to Cloudflare OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare. diff --git a/packages/cloudflare/README.md b/packages/cloudflare/README.md index 9b10592e..79be9991 100644 --- a/packages/cloudflare/README.md +++ b/packages/cloudflare/README.md @@ -34,7 +34,6 @@ You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/ - you can use the regular `next` CLI to start the Next.js dev server: - ## Local preview Run the following commands to preview the production build of your application locally: @@ -44,6 +43,7 @@ Run the following commands to preview the production build of your application l ```bash pnpx cloudflare ``` + - Preview the app in Wrangler ```bash @@ -60,6 +60,6 @@ Deploy your application to production with the following: pnpx cloudflare ``` -```bash -pnpm wrangler deploy -``` + ```bash + pnpm wrangler deploy + ```