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:
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 dogs
Install the static adapter
npm i -D @sveltejs/adapter-static
/src/routes/layout.js
Create 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:
Settings > Pages
. Enable GitHub Pages for your project.svelte.config.js
file 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.yml
File:
deploy.yml
file and customize it as needed to align with your project’s requirements.Verify the Default Branch:
master
. If your repository uses a different default branch (e.g., main), make sure to update the branch reference in the deploy.yml
file.