Closed zeljkomarinkovic closed 2 years ago
Hello !
The solution is actually hinted by the backend integration doc from vite, you also have solutions https://github.com/vitejs/vite/issues/341#issuecomment-657039140 here and https://github.com/vitejs/vite/issues/1984 here
I edited the vite() function like this :
function vite(string $entry)
{
$vite_host = VITE_HOST;
if (isDev()) {
return <<<HTML
<script type="module">
import RefreshRuntime from "{$vite_host}/@react-refresh"
window.\$RefreshReg$ = () => {}
window.\$RefreshSig$ = () => (type) => type
RefreshRuntime.injectIntoGlobalHook(window)
window.__vite_plugin_react_preamble_installed__ = true
</script>
<script type="module" src="{$vite_host}/@vite/client"></script>
<script type="module" src="{$vite_host}/assets/js/website.js"></script>
<script src="{$vite_host}/{$entry}" type="module" defer></script>
HTML;
} else {
return "\n" . jsTag($entry)
. "\n" . jsPreloadImports($entry)
. "\n" . cssTag($entry);
}
}
Sorry, I don't use React. Will leave this open in case someone finds the problem. Thanks all
@DitaXoXo Sorry for late reply. Yeah, the solution was like you said in Vite docs, glad you worked that out.
Thanks guys. Added this information to the README. Best regards
this is example for svelte https://github.com/ainaarawaida/svelte-php-framework
I have tested it with semi success. Works only with legacy codebase not with functional components.
Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong. See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201 at Button.jsx:1:1
Have someone had similar problems?