Konrad Höffner
Konrad Höffner

Reputation: 12207

How to export static HTML from Svelte without Surge or Vercel?

I want to publish my Svelte web app to GitHub pages and based my application on the template https://github.com/sveltejs/template. When I run npm run build, public/build/bundle.js is created but no index.html. All the tutorials I found talk about how to deploy Sapper projects, or to use external tools like Vercel and Surge, but is it possible to just build Svelte without any external tools? All I want is a static HTML page that I can copy to GitHub pages.

Edit: See the accepted answer for the general approach, however for non-root-directory-deployment, you still need to make the paths relative. I created a pull request at https://github.com/sveltejs/template/pull/239.

Upvotes: 1

Views: 2923

Answers (1)

OmG3r
OmG3r

Reputation: 1811

In svelte, index.html is a static file which will import your bundle.js and run it.

index.html is located at /public/index.html while your bundle.js is located at /public/build/bundle.js

in svelte template, index.html imports /build/bundle.js using a script tag to initialize the application.

while deploying, you just need to upload the whole /public folder and everything should be operational.

Upvotes: 3

Related Questions