web dev//Vite

Vite is a bundler and dev server for the frontend, and it does two different things depending on the mode. It only handles the frontend: the backend (API, database) needs a separate process, which in the Cloudflare stack is Wrangler. In development the two run in two terminals, Vite on 5173 with the frontend and Wrangler on 8788 with the API and D1; in production Pages serves everything together from `dist/`.


Vite is a bundler and dev server for the frontend, and it does two different things depending on the mode. It only handles the frontend: the backend (API, database) needs a separate process, which in the Cloudflare stack is Wrangler. In development the two run in two terminals, Vite on 5173 with the frontend and Wrangler on 8788 with the API and D1; in production Pages serves everything together from dist/.

In dev mode (npm run dev, port 5173 by default) it serves files from memory, with no dist/ generated, and it is fast because it uses native ES modules instead of bundling everything. With HMR, a changed file updates its component in the browser without a full page reload, and a built-in dev proxy can forward /api/* requests to another port (e.g. Wrangler on 8788).

In build mode (npm run build) it compiles all the source into static files in dist/ (build): it minifies, tree-shakes, code-splits and generates hashes for cache-busting, with Rollup under the hood.