This gist has most of the things I've used to develop the frontend using vite inside a monolithic django app.
Here's a boilerplate that uses this approach: https://github.com/labcodes/django-react-boilerplate
A couple of things to note:
- it runs in SPA mode by default. If you want SSR, you may want to look into django_vite;
- static files unrelated to your app, like images or fonts, should be served by django, instead of imported directly inside your frontend app;
- you'll need to enable manifest in your vite configs for production;
I've only tested this with a React app, but I'll share my notes when testing with a Svelte app later.- I've already tested with svelte, and the changes are really small! For the most part, you'll only need to remove react-specific stuff (like react-refresh), use a svelte + vite app as base, and change
base.html
to importmain.js
instead ofjsx
. And I've created a sample template for it too!
- I've already tested with svelte, and the changes are really small! For the most part, you'll only need to remove react-specific stuff (like react-refresh), use a svelte + vite app as base, and change
Besides that, just read the comments carefully and everything should work out. Whenever I'm free, I'll make a video about this and add the URL here :]
I've published a video on how to do it, step-by-step: https://www.youtube.com/watch?v=FCyYIVfDkhY