Adapter for SvelteKit apps that prerenders your site as a collection of static files for GitHub Pages

Overview

svelte-adapter-github

Adapter for SvelteKit apps that prerenders your site as a collection of static files for GitHub Pages.

Usage

Install with npm i -D svelte-adapter-github, then add the adapter to your svelte.config.js:

// svelte.config.js
import adapter from 'svelte-adapter-github';

export default {
	kit: {
		adapter: adapter({
			// default options are shown
			pages: 'docs',
			assets: 'docs',
			domain: null,
			jekyll: false,
			fallback: null,
			precompress: false
		})
	}
};

Unless you're in SPA mode, the adapter will attempt to prerender every page of your app, regardless of whether the prerender option is set.

Options

pages

The directory to write prerendered pages to. It defaults to docs.

assets

The directory to write static assets (the contents of static, plus client-side JS and CSS generated by SvelteKit) to. Ordinarily this should be the same as pages, and it will default to whatever the value of pages is, but in rare circumstances you might need to output pages and assets to separate locations.

domain

If you're using a custom domain on GitHub pages, include it here as type string. This will create a CNAME file in your build directory, with the domain as its contents.

jekyll

GitHub Pages defaults to using jekyll to build your site's files. However, this isn't generally needed when deploying a static svelte site. So, by default, we create an empy .nojekyll file in your build directory. If you need the jekyll build step, set this option to true and read the GitHub Pages section.

fallback

Specify a fallback page for SPA mode, e.g. index.html or 200.html or 404.html.

precompress

If true, precompresses files with brotli and gzip. This will generate .br and .gz files.

SPA mode

You can use adapter-static to create a single-page app or SPA by specifying a fallback page.

In most situations this is not recommended: it harms SEO, tends to slow down perceived performance, and makes your app inaccessible to users if JavaScript fails or is disabled (which happens more often than you probably think).

The fallback page is a blank HTML page that loads your SvelteKit app and navigates to the correct route. For example Surge, a static web host, lets you add a 200.html file that will handle any requests that don't otherwise match. We can create that file like so:

// svelte.config.js
import adapter from '@sveltejs/adapter-static';

export default {
	kit: {
		adapter: adapter({
			fallback: '200.html'
		})
	}
};

When operating in SPA mode, only pages that have the prerender option set will be prerendered.

GitHub Pages

When building for GitHub Pages - and if you're not using a custom domain - make sure to update paths.base to match your repo name; since the site will be served from https://your-username.github.io/your-repo-name rather than from the root.

By default, we provide a .nojekyll file, to prevent GitHub Pages from using Jekyll to manage your site. If you do not want to disable Jekyll, pass in the jekyll: true adapter option and change the kit's appDir configuration option to 'app_' or anything not starting with an underscore. For more information, see GitHub's Jekyll documentation.

A config for GitHub Pages - not using a custom domain - might look like the following:

const dev = process.env.NODE_ENV === 'development';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	...
	kit: {
		...
		paths: {
			base: dev ? '' : '/your-repo-name',
		},
		// If you are not using a .nojekyll file, change your appDir to something not starting with an underscore.
		// For example, instead of '_app', use 'app_', 'internal', etc.
		appDir: 'internal',
	}
};

License

MIT

You might also like...

Integrate Tauri in a Vite project to build cross-platform apps.

vite-plugin-tauri Integrate Tauri in a Vite project to build cross-platform apps Install Make sure to setup your environment for Tauri development. Th

Dec 15, 2022

A Svelte SPA Template for simple SPA Apps without using svelte kit.

Svelte SPA Template A Svelte Single Page Application Template for simple SPA Apps without using Svelte Kit or Sapper. New Project To create a new proj

Jan 24, 2022

🖼 Image Presets for Vite.js apps

vite-plugin-image-presets Image Presets for Vite.js apps This Vite plugin allows you to define presets for image processing using Sharp, allowing you

Dec 29, 2022

Create Nuxt3 apps with zero effort.

Create Nuxt3 Create Nuxt3 apps with zero effort. Features Select UI frameworks and install it from list Install extra modules like '@nuxt/content' Ins

Jul 9, 2022

🌈 what's your GitHub profile color?

🌈 what's your GitHub profile color?

🌈 OctoColor 🤔 Wanna know what's your GitHub Profile Color? 🐱 Head over to https://octocolor.vercel.app 🐱‍💻 How does GitColor work? The idea is si

Sep 22, 2022

Resolve all resource files dynamic publicPath

vite-plugin-dynamic-base 🦾 Resolve all resource files dynamic publicPath, like Webpack's __webpack_public_path__. Installation npm i vite-plugin-dyna

Jan 4, 2023

🐝 A vite plugin automatically export files & HMR support

🐝 A vite plugin automatically export files & HMR support

vite-plugin-hot-export Automatically export files with HMR English|简体中文 Why ? When developing, we often need to download some images or svg from the i

Nov 12, 2022

Replace files during Vite build - handy when replacing strings is not enough

vite-plugin-replace-files Replace files during Vite build - handy when replacing strings is not enough. Install Install with your favorite package man

Sep 21, 2022

:tada: A magical vue admin https://panjiachen.github.io/vue-element-admin

:tada: A magical vue admin                                                                https://panjiachen.github.io/vue-element-admin

English | 简体中文 | 日本語 | Spanish SPONSORED BY 活动服务销售平台 客户消息直达工作群 Introduction vue-element-admin is a production-ready front-end solution for admin inter

Dec 31, 2022
Comments
  • `Error: writeStatic has been removed. Please ensure you are using the latest version of svelte-adapter-github`

    `Error: writeStatic has been removed. Please ensure you are using the latest version of svelte-adapter-github`

    This error appears when I try to build my project with most currently recent versions:

    • "@sveltejs/kit": "1.0.0-next.405",
    • "svelte-adapter-github": "0.0.1-next.0",

    When I try to use older @sveltejs/kit, I bump into this another issue:

    Therefore I need to downgrade my @sveltejs/kit so much, that everything else just breaks up: and consecutively I need to downgrade almost everything to who knows which version, in order to find this short period of time when all this stack worked, for building SveltKit project for Github.

    opened by jerrygreen 5
  • builder.prerender() has been removed.

    builder.prerender() has been removed.

    Hi, getting this error...

    > Using svelte-adapter-github
    > builder.prerender() has been removed. Prerendering now takes place in the build phase — see builder.prerender and builder.writePrerendered
        at Object.prerender (file:///Users/orefalo/GitRepositories/svelte-related/svelte-splitpanes/node_modules/@sveltejs/kit/dist/chunks/index4.js:161:10)
        at adapt (file:///Users/orefalo/GitRepositories/svelte-related/svelte-splitpanes/node_modules/svelte-adapter-github/index.js:21:18)
        at adapt (file:///Users/orefalo/GitRepositories/svelte-related/svelte-splitpanes/node_modules/@sveltejs/kit/dist/chunks/index4.js:180:8)
        at file:///Users/orefalo/GitRepositories/svelte-related/svelte-splitpanes/node_modules/@sveltejs/kit/dist/cli.js:935:11
    
    opened by orefalo 3
Owner
null
Minimal, zero-configuration and fast solution for static site generation in any front-end framework.

Staticit - Introduction Whether you want to increase performance of your web application or improve SEO. Generally you have 2 options, use SSR (Server

Engineerhub 4 Jun 11, 2022
Automatically configure Vitest from your SvelteKit configuration.

vitest-svelte-kit Automatically configure Vitest from your SvelteKit configuration. Getting Started Installing In an existing SvelteKit project, run t

Nick Breaton 44 Dec 30, 2022
A template repository / quick start to build Azure Static Web Apps with a Node.js function. It uses Vue.js v3, Vue Router, Vuex, and Vite.js.

Azure Static Web App Template with Node.js API This is a template repository for creating Azure Static Web Apps that comes pre-configured with: Vue.js

Marc Duiker 6 Jun 25, 2022
Small library to accomplish common tasks in Svelte/SvelteKit

svelte-utilities svelte-utilities is a small utilities library for Svelte/SvelteKit that provides features I use in almost every project, such as: Laz

null 40 Nov 25, 2022
Configure multi-pages applications and code splitting

vite-plugin-mp Configure multi-pages applications and code splitting Usage npm install vite-plugin-mp -D // vite.config.js import { defineConfig } fro

null 15 Dec 2, 2022
:fire::fire::fire: 强大的动态表单生成器|form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions through JSON.

form-create form-create is a form generation component that can generate dynamic rendering, data collection, verification and submission functions thr

xaboy 4.6k Jan 3, 2023
Collection of CSS box-shadows for every taste contains more than 100 simple, beautiful and airy shadows.

Vue Box-shadows Collection of CSS box-shadows for every taste contains more than 100 simple, beautiful and airy shadows. Add beautiful shadow effects

Andrej Sharapov 29 Nov 14, 2022
Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.

Onsen UI - Cross-Platform Hybrid App and PWA Framework Onsen UI is an open source framework that makes it easy to create native-feeling Progressive We

null 8.7k Jan 4, 2023
Vue Native is a framework to build cross platform native mobile apps using JavaScript

Vue Native Visit our website at vue-native.io or read the official documentation here. Build native mobile apps using Vue Vue Native is a framework to

GeekyAnts 8.4k Jan 6, 2023
Light speed setup for MEVN(Mongo Express Vue Node) Apps

Light speed setup for MEVN stack based web-apps Chat: Telegram Donate: PayPal, Open Collective, Patreon A CLI tool for getting started with the MEVN s

madlabsinc 791 Dec 14, 2022