Skip to content Skip to sidebar Skip to footer

Run A Svelte App From File:// With No Sever

I need to run a Svelte app and be able to execute it without a server. With other frameworks this is possible as it is just javascript but I can't find a way to just click my inde

Solution 1:

I need to run a Svelte app and be able to execute it without a server. With other frameworks this is possible as it is just javascript but I can't find a way to just click my index.html and run my app built with Svelte

I'll break it down into two components, building and executing the svelte app.

Firstly, you require a computer to build the Svelte app as it executes rollup (and runs a node server) to perform the compilation, but this isn't what the OP is asking for...

To address the execution of the Svelte app, you can execute this without a running server.

Please see attached

screenshot

You are given a npm run build from the Svelte create-svelte app generate command which outputs a public.html.

This can be used to host the file say, on Surge.sh, however to make this "local file friendly", You will need to edit the outputting html to the following (i.e. remove base /).

original source index.html

<linkrel='icon'type='image/png'href='/favicon.png'><linkrel='stylesheet'href='global.css'><linkrel='stylesheet'href='/build/bundle.css'><scriptdefersrc='/build/bundle.js'></script>

Final html

<!DOCTYPE html><htmllang="en"><head><metacharset='utf-8'><metaname='viewport'content='width=device-width,initial-scale=1'><title>Svelte app</title><linkrel='icon'type='image/png'href='favicon.png'><linkrel='stylesheet'href='global.css'><linkrel='stylesheet'href='build/bundle.css'><scriptdefersrc='build/bundle.js'></script></head><body></body></html>

Post a Comment for "Run A Svelte App From File:// With No Sever"