DogApp is a toy project designed to demonstrate how to deploy a SvelteKit app as a static site. This requires modifying the default build process to support Static Site Generation (SSG). This project is also on gh pages.
Current Versions Used:
- Svelte 5
- SvelteKit 2
Additional Resources: For detailed guidance on configuring the project as a static website, refer to the official SvelteKit documentation:
Create a svelte project (if necessary)
npx sv create dogsInstall the static adapter
npm i -D @sveltejs/adapter-staticCreate a file +layout.js with the content:
// This can be false if you're using a fallback (i.e. SPA mode)
export const prerender = true;Configure the static adapter, edit svelte.config.js and replace the content to:
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
strict: true
})
}
};
export default config;DONE.
Follow these steps only if you plan to deploy this project on GitHub Pages:
- Enable GitHub Pages:
Go to your repository's settings and navigate to
Settings > Pages. Enable GitHub Pages for your project. - Update svelte.config.js
Edit the
svelte.config.jsfile to configure the paths property with your project's name. For example:
import adapter from '@sveltejs/adapter-static';
/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
paths: {
base: process.argv.includes('dev') ? '' : `/dogs` // <= project name
},
adapter: adapter({
pages: 'build',
assets: 'build',
fallback: undefined,
precompress: false,
strict: true
})
}
};
export default config;This step is only required if you plan to automate the build process using GitHub Actions.
-
Review the
deploy.ymlFile:- Open the
deploy.ymlfile and customize it as needed to align with your project’s requirements.
- Open the
-
Verify the Default Branch:
- The default branch in the configuration is set to
master. If your repository uses a different default branch (e.g., main), make sure to update the branch reference in thedeploy.ymlfile.
- The default branch in the configuration is set to