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

Host Static SPA written in HTML/JS in WebView2

$
0
0

I have created a Static SPA using SvelteKit, and i want to open the application in Revit using WebView2. The compiled file structure of my application looks like this:

build- index.html- favicon.png- _app  - env.js  - version.json  - immutable    - chunks      - disclose-version.BtJd_2Dd.js      - entry.D6WgGb8s.js      - proxy.C4KmojzZ.js      - render.zjJFQd9i.js      - runtime.4rquTwgo.js    - entry      - app.Cc30Kppw.js      - start.BjQAhHL7.js    - nodes      - 0.rlw-XIZ8.js      - 1.BWC29Vl1.js      - 2.CteRqxFd.js

And my index.html file looks like this:

<!doctype html><html lang="en"><head><meta charset="utf-8" /><link rel="icon" href="/favicon.png" /><meta name="viewport" content="width=device-width, initial-scale=1" /><link rel="modulepreload" href="/_app/immutable/entry/start.BjQAhHL7.js"><link rel="modulepreload" href="/_app/immutable/chunks/entry.D6WgGb8s.js"><link rel="modulepreload" href="/_app/immutable/chunks/runtime.4rquTwgo.js"><link rel="modulepreload" href="/_app/immutable/entry/app.Cc30Kppw.js"><link rel="modulepreload" href="/_app/immutable/chunks/render.zjJFQd9i.js"><link rel="modulepreload" href="/_app/immutable/chunks/disclose-version.BtJd_2Dd.js"><link rel="modulepreload" href="/_app/immutable/chunks/proxy.C4KmojzZ.js"></head><body data-sveltekit-preload-data="hover"><div style="display: contents"><script>                {                    __sveltekit_v04hc = {                        base: ""                    };                    const element = document.currentScript.parentElement;                    Promise.all([                        import("/_app/immutable/entry/start.BjQAhHL7.js"),                        import("/_app/immutable/entry/app.Cc30Kppw.js")                    ]).then(([kit, app]) => {                        kit.start(app, element);                    });                }</script></div></body></html>

I have tried to host the application using npx serve and this works flawlessly.

Now i try to host it through WebView2. I write the following C# code:

webView.CoreWebView2.SetVirtualHostNameToFolderMapping("app.revitfoundry","C:\\path\\to\\my\\app\\build",    CoreWebView2HostResourceAccessKind.Allow);webView.Source = new Uri("https://app.revitfoundry/index.html");

When loading the web view, the application loads, but my application cannot find the index.html file:

Could not find /index.html

When inspecting the webview, all the files within the HTML/JS application are loaded into "Sources" and are stored in top->app.revitfoundry. Even the index.html file is stored here, which the application seems not to be able to find.

What could cause the error? Is it something with Svelte? If so, then i find it weird that the code works when running a server using npx serve. Is it maybe something wrong with the configurations of the webView?


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>