Last active
January 29, 2023 08:38
-
-
Save mandrasch/8b4c79713a00b56cb5040090a2151e59 to your computer and use it in GitHub Desktop.
Github Pages env var for SvelteKit (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .github/workflows/build-deploy.yaml | |
name: Build and Deploy | |
on: | |
push: | |
branches: | |
- main | |
# Sustainability: Don't trigger build for updated README | |
paths-ignore: | |
- '**/README.md' | |
# Allows you to run this workflow manually from the Actions tab. | |
# workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ๐๏ธ | |
uses: actions/checkout@v3 | |
- name: Use Node LTS | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' # lts | |
# This build runs with path prefix for github pages (hosted on subdirectory), | |
# for example https://<USER>.github.io/<REPO-NAME>/ | |
# See: https://kit.svelte.dev/docs/adapter-static#github-pages | |
- name: Install and Build for Github Pages ๐ง | |
run: | | |
npm ci | |
npm run build | |
env: | |
PATHS_BASE: '/${{ github.event.repository.name }}' | |
# Not needed currently: | |
#BASE_URL: 'https://${{ github.event.repository.owner.name }}.github.io/' | |
- name: Archive production artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-folder | |
path: | | |
build | |
- name: Deploy to Github Pages ๐ | |
uses: JamesIves/github-pages-deploy-action@v4 | |
with: | |
branch: gh-pages | |
folder: build #the output folder |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import adapter from '@sveltejs/adapter-static'; | |
import sveltePreprocess from 'svelte-preprocess'; | |
//import { env } from '$env/dynamic/private'; | |
let pathsBase = ''; | |
// https://stackoverflow.com/posts/67978668/revisions | |
if(process.env['PATHS_BASE'] != undefined){ | |
console.log('paths.base was set via node env variable',process.env.PATHS_BASE); | |
pathsBase = process.env.PATHS_BASE; | |
}else{ | |
console.log('No paths.base set, defaults to \'\''); | |
} | |
/** @type {import('@sveltejs/kit').Config} */ | |
const config = { | |
preprocess: sveltePreprocess(), | |
kit: { | |
// https://stackoverflow.com/a/72733222 | |
adapter: adapter({ | |
pages: 'build', | |
assets: 'build', | |
fallback: null, | |
precompress: false | |
}), | |
paths: { | |
base: pathsBase | |
// e.g. for github pages -> repository name: '/repository-name' | |
//https://kit.svelte.dev/docs/adapter-static#github-pages | |
} | |
} | |
}; | |
export default config; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment