django-vite
django-vite copied to clipboard
Add tag to render the react-refresh script
I wanted to raise another suggestion for django-vite.
When working with @vitejs/plugin-react-refresh
, we need to include this script to enable HMR.
<script type="module">
import RefreshRuntime from 'http://localhost:3000/@react-refresh'
RefreshRuntime.injectIntoGlobalHook(window)
window.$RefreshReg$ = () => {}
window.$RefreshSig$ = () => (type) => type
window.__vite_plugin_react_preamble_installed__ = true
</script>
It would be fantastic if we could have a {% vite_react_refresh_tag %}
or something similar to render this script. It would only render the script if DEBUG
is true.
Thanks again for your wonderful work on this library.
Ref: https://vitejs.dev/guide/backend-integration.html
Duplicate of #14
Hi, As I said in the #14, I think those things are project specific stuff and need to be implemented by project.
I can see where you're coming from. Certainly, not everyone will use be using @vitejs/plugin-react-refresh
.
However, in my eyes, the purpose of django-vite is to integrate Django with Vite. The @vitejs/plugin-react-refresh
is part of the improved development experience that Vite provides. It's an officially supported plugin.
The approach I proposed gives users of django-vite the option to opt-in to using @vitejs/plugin-react-refresh
without having to write an extra template tag.
I understand not wanting to work on this, but would you accept a PR if I opened one?
Yeah of course, feel free to do it.
I think this has been done with #53 but not released yet?
I think this has been done with #53 but not released yet?
Seems like it is released now in version 2.1.0 🎉