tl;dr
If you are importing the Vite generated bundle as a .js
file instead of via an HTML entry file, then you should follow the backend integration guide of the official docs.
Add necessary scripts
You will need @vite/client
and your bundle, in this case main.js
:
<script type="module" src="http://localhost:5173/@vite/client"></script><script type="module" src="http://localhost:5173/main.js"></script>
Add the code that modifies the HTML:
<script type="module"> import RefreshRuntime from 'http://localhost:5173/@react-refresh' RefreshRuntime.injectIntoGlobalHook(window) window.$RefreshReg$ = () => {} window.$RefreshSig$ = () => (type) => type window.__vite_plugin_react_preamble_installed__ = true</script>