I'm trying to use Svelte 5 and SvelteKit inside PHP.
I don't understand how to use the Imperative component API (https://svelte.dev/docs/svelte/imperative-component-api). Where do I put the following code? Do I put it in src/routes/main.js
?
import { mount } from 'svelte';import App from './App.svelte';const app = mount(App, { target: document.querySelector('#app'), props: { some: 'property' }});
If I use vite build -w
to build the project, what is the path of the built JavaScript to put inside the PHP?
<body><h1><?php echo "Hello, $user"; ?></h1><div id="app"></div><script src="/path/build/what-is-the-name-of-the-js-file-for-here.js"></script></body>
What do I set src/routes/+layout.js
to? My assumption is that I should first try making an SPA (https://svelte.dev/docs/kit/single-page-apps) with the following for src/routes/+layout.js
:
export const ssr = false;
I made a file with the JavaScript from the Imperative component API, but I don't see it in build/
.