How to build for React + Vite + Cloudflare worker? #4018
vickyRathee
started this conversation in
General
Replies: 2 comments 2 replies
-
|
/api/index.ts import { Hono } from "hono";
const app = new Hono<{ Bindings: Env }>();
app.get("/api/status", (c) => {
return c.json({ status: "ok" });
});
app.get("*", (c) => {
return c.env.ASSETS.fetch(c.req.raw);
});
export default app;import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
import tsconfigPaths from "vite-tsconfig-paths";
import { cloudflare } from "@cloudflare/vite-plugin";
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss(), tsconfigPaths(), cloudflare()],
});index.html wrangler.jsonc {
"$schema": "node_modules/wrangler/config-schema.json",
"name": "app-name",
"main": "./src/api/index.ts",
"compatibility_date": "2025-02-26",
"compatibility_flags": ["nodejs_compat"],
"assets": {
"binding": "ASSETS",
"directory": "./dist",
"not_found_handling": "single-page-application"
},
"observability": {
"enabled": true,
"head_sampling_rate": 1
}
}
|
Beta Was this translation helpful? Give feedback.
2 replies
-
|
@vickyRathee take a look at https://github.com/yusukebe/hono-vite-react-stack |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using this example provided by Cloudflare for Vite + React + Hono https://github.com/cloudflare/templates/tree/main/vite-react-template which works fine if I use it as-is.
But I need to change the static index.html to
index.tsxto serve the initial html by hono to add title, description, meta tags etc. based on the pathname.So, I changed the
index.htmlwithindex.tsxAnd, I also tried to change the vite config to add build from
import build from "@hono/vite-build/cloudflare-workers"but it doesn't work.Any suggestion will be really appreciated.
Beta Was this translation helpful? Give feedback.
All reactions