Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

Embedding Svelte 5 inside PHP (Imperative component API)

$
0
0

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/.


Viewing all articles
Browse latest Browse all 1541

Trending Articles