I wanted to try out Sveltekit, and I wanted some way to easily create and track my code for the Advent of Code site. Thus this repo was born. I started on StackBlitz, but I just couldn't get over how bad the file tree works. I can never tell what directory a file is in because the file is indented more than two levels past directories.
To get github pages to work, I found these links, none of which was complete or perfect:
- https://kit.svelte.dev/docs/adapters
- https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode
- https://github.com/sveltejs/kit/tree/master/packages/adapter-static#spa-mode
- https://kit.svelte.dev/docs/modules#$app-paths-base
Things I had to do:
import adapter from '@sveltejs/adapter-static';
const dev = process.argv.includes('dev');
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
fallback: 'index.html'
}),
prerender: { entries: [] },
paths: {
base: dev ? '' : '/sveltejs-kit-advent-of-code-2022',
},
}
};
export default config
- use
adapter-static
- set fallback to 'index.html'
- clear prerender entries
- use repo name as base for pages url
In /src/routes/+layout.svelte
:
export const ssr = false;
I also had to add that to some other pages (i.e. about) which
are normally statically rendered too. about
was necessary for sure because it had commands specifically to
render it ahead of time, while others without specifics are
probably handled by default layout.
In /src/routes/+_page.js
I did this:
export const prerender = false;
git commit -m "Building pages"
git checkout -B github-pages
pnpm run build
rm -rf docs
mv build docs
git add .
git commit -m "Github pages commit"
git push origin HEAD -f
git switch -
- commit to current branch (bad or not needed?)
- checkout
github-pages
branch at current commit - build, and rename 'build' directory to 'docs'
- add files and commit
- force push to github
- switch back to previous branch with '-'
This goes in /static/.nojekyll
so it will be in our
/docs directory and tell github not to use it's jekyll
build tool since we have the site how we want.
In the repo settings on the left is a 'Pages' selection. I enabled it there and set the branch to 'github-pages' and the folder to '/docs'. For some reason the only folders that show are docs and root. Moving the build files to a docs directory enabled me to keep the build directory in .gitignore, so that was nice anway.