Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
antonrom1 committed Sep 4, 2023
0 parents commit 88e02fd
Show file tree
Hide file tree
Showing 38 changed files with 2,539 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Deploy to GitHub Pages

on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Install and Build
run: |
npm install
npm run build
- name: Deploy to GitHub Pages
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: build
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
node_modules
.svelte-kit
build
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/sveltekit-gh-pages.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# antonrom1.github.io

> Minimal static, pre-rendered [SvelteKit](https://kit.svelte.dev/) set-up made deployable to [GitHub Pages](https://metonym.github.io/sveltekit-gh-pages/).
## 1) Use the static adapter

Install the [SvelteKit static adapter](https://github.com/sveltejs/kit/tree/master/packages/adapter-static) to prerender the app.

**package.json**

```diff
"devDependencies": {
+ "@sveltejs/adapter-static": "^2.0.3",
"@sveltejs/kit": "^1.22.6",
"gh-pages": "^5.0.0",
"svelte": "^4.2.0",
"vite": "^4.4.9"
}
```

**svelte.config.js**

```diff
+ import adapter from "@sveltejs/adapter-static";

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
+ adapter: adapter(),
},
};

export default config;

```

Ensure your top-level `+layout.js` exports `prerender = true`.

```js
// src/routes/+layout.js
export const prerender = true;
```

## 2) Modify `paths.base` in the config

`kit.paths.base` should be your repo URL subpath (see the [Vite docs](https://vitejs.dev/guide/static-deploy.html#github-pages)). In the example below, replace `/sveltekit-gh-pages` with your repository name.

```diff
import adapter from "@sveltejs/adapter-static";

/** @type {import('@sveltejs/kit').Config} */
const config = {
kit: {
adapter: adapter(),
+ paths: {
+ base: process.env.NODE_ENV === "production" ? "/sveltekit-gh-pages" : "",
+ },
},
};

export default config;

```

**Note:** You will also need to prepend relative paths with the [SvelteKit `base` path](https://kit.svelte.dev/docs/modules#$app-paths) so that your app can build successfully for production.

```svelte
<script>
import { base } from "$app/paths";
</script>
<a href="{base}/about">About</a>
```

## 3) Add a `.nojekyll` file to the `/static` folder

The last step is to add an empty `.nojekyll` file to the static folder to [bypass Jekyll on GitHub Pages](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/). SvelteKit will copy `static` assets to the final build folder.

**package.json**

```json
{
"scripts": {
"dev": "vite dev",
"build": "vite build",
"deploy": "gh-pages -d build -t true"
}
}
```

**The `deploy` script**

The deploy script instructs `gh-pages` to do the following:

- `-d build`: Publish the `build` folder
- `-t true`: Include dotfiles (e.g., `.nojekyll`)

---

## Quick start

Use [degit](https://github.com/Rich-Harris/degit) to quickly scaffold a new project:

```sh
npx degit metonym/sveltekit-gh-pages my-app
cd my-app && yarn install
```

## Deploying to GitHub Pages

First, build the app by running `yarn build`.

Then, run `yarn deploy` to deploy the app to GitHub Pages.
6 changes: 6 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"ignoreDeprecations": "5.0"
}
}
Loading

0 comments on commit 88e02fd

Please sign in to comment.