Deploy Svelte app in Github Pages
With giants in the Frontend-Framework world like React
and Angular
, Svelte
the underdog has seen an tremendous growth among the developers and within the community since its inception in 2016.
Take a look at the results of StateOfJs survey here
Create a GitHub Project
After creating a new GitHub account or signing into your account, the dashboard page opens.
By clicking the New
button, create a new project.
Enter a project name and the visibilty should be public
. This is because, for Free account, only “public” projects can publish using GitHub Pages.
Enable GitHub Pages
In the GitHub project, do the following steps
- Navigate to
Settings
tab - Select
Pages
from the sidebar - Make sure under Source,
GitHub Actions
is selected
That all you need to do for now.
Setup a svelte project
In this post, we are going to look into a basic Svelte
project and not SVELTEKIT based app.
-
Create svelte project.
-
Choose the option
Svelte
and language of your choice, here I have selectedTypescript
. -
Exceute the following commands, to check whether the development server starts.
-
The server should be started at http://localhost:5173/
-
Open the project in
VS Code
. The project structure should like this.- index.html
- package.json
- package-lock.json
Directorynode_modules/
- …
Directorypublic
- vite.svg
- README.md
Directorysrc
- app.css
- App.svelte Starting point for svelte-projects
Directoryassets
- svelte.svg
Directorylib
- Counter.svelte
- main.ts
- vite-env.d.ts
- svelte.config.js
- tsconfig.json
- tsconfig.node.json
- vite.config.ts
Update vite.config.ts
file
Create workflow file
In order to deploy to GitHub Pages, create a file deploy.yml
in the folder .github/workflows
Directory.github
Directoryworkflows
- deploy.yml
- index.html
- package.json
- …
Copy the following contents into the file.
Upload the project
Now save its time to create the initial commit and upload the project to GitHub. Follow the following commands
- Initialize Git Repo
- Add files and write the commit message
- Setup the remote origin. Change the URL according to your project.
- Push the commit to remote repository
Reviewing GitHub Actions
After the initial commit, go to the project in GitHub website. Under the tab Actions
, you can see a 1 workflow run
.
A successfully completed job looks like this below. And the website is hosted under https://santhosh2r2.github.io/svelte-github-pages/
The final website should look below.
Next steps
Now you have a svelte project deployed in GitHub and made available for everyone.
Have fun making your next project.