Skip to content

Commit 507ad74

Browse files
Migrate Cloudflare template to official Vite plugin (#95)
1 parent f20b64c commit 507ad74

File tree

8 files changed

+922
-90
lines changed

8 files changed

+922
-90
lines changed

cloudflare/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
# Cloudflare
1010
.mf
1111
.wrangler
12+
.dev.vars*
13+

cloudflare/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99
"typecheck": "wrangler types && react-router typegen && tsc -b"
1010
},
1111
"dependencies": {
12-
"@react-router/node": "*",
13-
"@react-router/serve": "*",
1412
"isbot": "^5.1.17",
1513
"react": "^19.0.0",
1614
"react-dom": "^19.0.0",
17-
"react-router": "*"
15+
"react-router": "^7.3.0"
1816
},
1917
"devDependencies": {
20-
"@react-router/dev": "*",
18+
"@cloudflare/vite-plugin": "^0.1.11",
19+
"@react-router/dev": "^7.3.0",
2120
"@tailwindcss/vite": "^4.0.0",
2221
"@types/node": "^20",
2322
"@types/react": "^19.0.1",
2423
"@types/react-dom": "^19.0.1",
2524
"tailwindcss": "^4.0.0",
2625
"typescript": "^5.7.2",
27-
"vite": "^5.4.11",
26+
"vite": "^6.2.1",
2827
"vite-tsconfig-paths": "^5.1.4",
2928
"wrangler": "^4.0.0"
3029
}

cloudflare/react-router.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import type { Config } from "@react-router/dev/config";
22

33
export default {
4-
// Config options...
5-
// Server-side render by default, to enable SPA mode set this to `false`
64
ssr: true,
5+
future: {
6+
unstable_viteEnvironmentApi: true,
7+
},
78
} satisfies Config;

cloudflare/vite.config.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
import { reactRouter } from "@react-router/dev/vite";
2-
import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";
2+
import { cloudflare } from "@cloudflare/vite-plugin";
33
import tailwindcss from "@tailwindcss/vite";
44
import { defineConfig } from "vite";
55
import tsconfigPaths from "vite-tsconfig-paths";
66

7-
export default defineConfig(({ isSsrBuild }) => ({
8-
build: {
9-
rollupOptions: isSsrBuild
10-
? {
11-
input: "./workers/app.ts",
12-
}
13-
: undefined,
14-
},
7+
export default defineConfig({
158
plugins: [
16-
cloudflareDevProxy({
17-
getLoadContext({ context }) {
18-
return { cloudflare: context.cloudflare };
19-
},
20-
}),
9+
cloudflare({ viteEnvironment: { name: "ssr" } }),
2110
tailwindcss(),
2211
reactRouter(),
2312
tsconfigPaths(),
2413
],
25-
}));
14+
});

cloudflare/workers/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ declare module "react-router" {
1414
}
1515

1616
const requestHandler = createRequestHandler(
17-
// @ts-expect-error - virtual module provided by React Router at build time
17+
// @ts-expect-error - virtual module provided by React Router
1818
() => import("virtual:react-router/server-build"),
1919
import.meta.env.MODE
2020
);
2121

2222
export default {
23-
fetch(request, env, ctx) {
23+
async fetch(request, env, ctx) {
2424
return requestHandler(request, {
2525
cloudflare: { env, ctx },
2626
});

cloudflare/wrangler.jsonc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "node_modules/wrangler/config-schema.json",
3+
"name": "react-router-app",
4+
"compatibility_date": "2025-02-24",
5+
"main": "./workers/app.ts",
6+
"assets": {},
7+
"vars": {
8+
"VALUE_FROM_CLOUDFLARE": "Hello from Cloudflare"
9+
}
10+
}

cloudflare/wrangler.toml

Lines changed: 0 additions & 8 deletions
This file was deleted.

pnpm-lock.yaml

Lines changed: 897 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)