From 5503b7ef4424aec53e3d98c0e9ede91491b84ea9 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Mon, 23 Sep 2024 13:36:59 +0100 Subject: [PATCH 1/2] Update create-next-app page.tsx to match latest --- examples/create-next-app/src/app/page.tsx | 144 ++++++++++++---------- 1 file changed, 80 insertions(+), 64 deletions(-) diff --git a/examples/create-next-app/src/app/page.tsx b/examples/create-next-app/src/app/page.tsx index 1179ed2a..25977bc4 100644 --- a/examples/create-next-app/src/app/page.tsx +++ b/examples/create-next-app/src/app/page.tsx @@ -2,94 +2,110 @@ import Image from "next/image"; export default function Home() { return ( -
-
- Next.js logo -
    -
  1. - Get started by editing{" "} - - src/app/page.tsx - - . -
  2. -
  3. Save and see your changes instantly.
  4. -
- -
+
+
+

+ Get started by editing  + src/app/page.tsx +

+ -
-
+
+ +
+ Next.js Logo +
+ +
+ +

+ Docs{" "} + + -> + +

+

+ Find in-depth information about Next.js features and API. +

+
+ - File icon - Learn +

+ Learn{" "} + + -> + +

+

+ Learn about Next.js in an interactive course with quizzes! +

+ - Window icon - Examples +

+ Templates{" "} + + -> + +

+

Explore starter templates for Next.js.

+ - Globe icon - Go to nextjs.org → +

+ Deploy{" "} + + -> + +

+

+ Instantly deploy your Next.js site to a shareable URL with Vercel. +

- -
+
+ ); } From 0cdf44b3c276f0826947caa32321b50d5539bee3 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Mon, 23 Sep 2024 13:37:12 +0100 Subject: [PATCH 2/2] fix: add support for serving static assets in the `public` directory See https://nextjs.org/docs/pages/building-your-application/optimizing/static-assets --- examples/create-next-app/public/next.svg | 1 + examples/create-next-app/public/vercel.svg | 1 + packages/cloudflare/src/build/build-worker.ts | 12 +++++++++++- packages/cloudflare/src/build/build.ts | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 examples/create-next-app/public/next.svg create mode 100644 examples/create-next-app/public/vercel.svg diff --git a/examples/create-next-app/public/next.svg b/examples/create-next-app/public/next.svg new file mode 100644 index 00000000..5174b28c --- /dev/null +++ b/examples/create-next-app/public/next.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/create-next-app/public/vercel.svg b/examples/create-next-app/public/vercel.svg new file mode 100644 index 00000000..d2f84222 --- /dev/null +++ b/examples/create-next-app/public/vercel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/cloudflare/src/build/build-worker.ts b/packages/cloudflare/src/build/build-worker.ts index 94165d41..349482a2 100644 --- a/packages/cloudflare/src/build/build-worker.ts +++ b/packages/cloudflare/src/build/build-worker.ts @@ -1,6 +1,6 @@ import { NextjsAppPaths } from "../nextjs-paths"; import { build, Plugin } from "esbuild"; -import { readFileSync } from "node:fs"; +import { existsSync, readFileSync } from "node:fs"; import { cp, readFile, writeFile } from "node:fs/promises"; import { patchRequire } from "./patches/investigated/patch-require"; @@ -20,6 +20,7 @@ import { updateWebpackChunksFile } from "./patches/investigated/update-webpack-c * @param nextjsAppPaths */ export async function buildWorker( + inputNextAppDir: string, outputDir: string, nextjsAppPaths: NextjsAppPaths, templateSrcDir: string @@ -124,10 +125,19 @@ Request = globalThis.Request; await updateWorkerBundledCode(workerOutputFile, nextjsAppPaths); console.log(`\x1b[35m⚙️ Copying asset files...\n\x1b[0m`); + + // Copy over client-side generated files await cp(`${nextjsAppPaths.dotNextDir}/static`, `${outputDir}/assets/_next/static`, { recursive: true, }); + // Copy over any static files (e.g. images) from the source project + if (existsSync(`${inputNextAppDir}/public`)) { + await cp(`${inputNextAppDir}/public`, `${outputDir}/assets`, { + recursive: true, + }); + } + console.log(`\x1b[35mWorker saved in \`${workerOutputFile}\` 🚀\n\x1b[0m`); } diff --git a/packages/cloudflare/src/build/build.ts b/packages/cloudflare/src/build/build.ts index e4bbec39..add90c5d 100644 --- a/packages/cloudflare/src/build/build.ts +++ b/packages/cloudflare/src/build/build.ts @@ -43,7 +43,7 @@ export async function build(inputNextAppDir: string, opts: BuildOptions): Promis const templateDir = path.join(path.dirname(fileURLToPath(import.meta.url)), "templates"); - await buildWorker(outputDir, nextjsAppPaths, templateDir); + await buildWorker(inputNextAppDir, outputDir, nextjsAppPaths, templateDir); } type BuildOptions = {