Project Architecture¶
Vite¶
Here's how Vite fits into this Django + HTMX project:
The big picture¶
Vite is the JS bundler — its only real job here is to take frontend/main.js (which imports htmx + the SSE extension) and turn it into one browser-ready file. The actual UI is server-rendered Django templates + HTMX partials; Vite never touches the HTML or CSS (those live in static/ and are served directly by Django/Caddy).
The pieces¶
-
Entry point — frontend/main.js imports htmx and htmx-ext-sse from npm, then wires up the small amount of client-side behavior (dialog handling, view transitions, 400-swap fix). These npm packages are dependencies in package.json; Vite resolves and bundles them.
-
Config — vite.config.js:
- base: "/static/" — built assets get /static/-prefixed URLs, matching Django's STATIC_URL
- build.outDir: "dist" with manifest: true — outputs dist/assets/main-
.js plus dist/.vite/manifest.json mapping the source name to the hashed file -
input: "frontend/main.js" — the single entry
-
django-vite bridge — base.html does {% load django_vite %}, then:
- {% vite_hmr_client %} — in dev, injects the Vite HMR client
- {% vite_asset "frontend/main.js" %} — emits the right