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
about the other comments: lately I've been lacking time (and peace of mind) to test out the other suggestions, like the ones to refactor the template tag.
it would be awesome if someone could create a simple sample project with the refactored template tag + tests, so I could be sure everything is working and merge the changes here.
@seplveda , about your comment, I can't work on that right now, but there is a working boilerplate for you to base prometheus on: https://github.com/labcodes/django-react-boilerplate
I'll add it on the readme as well, for future reference