I'm surely not maintaining this as well as I could. There are also other possible, better integrated solutions, like django-vite, so keep in mind this was supposed to be more of a note to myself than anything :]
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
thanks for the notes @pedrovgp ! I'm glad you could make it work, and I hope to use your changes soon.
also, just as a note, I'm very, very busy with moving and work, so I added a couple of warnings on the base gist. :]
make sure to take a look at django-vite too, seems to be a better integrated solution. I didn't really try it, but I will when I have the time so I can leave more notes here.