From 20105c153474cc19d0672f8c74ac441bfcd771cf Mon Sep 17 00:00:00 2001 From: Jackson Hoffart Date: Fri, 26 Jul 2024 12:38:09 +0200 Subject: [PATCH] feat: make site static, and deploy to GH pages (#13) * gains adapter-static * build site statically * set-up to deploy using GitHub actions --- .github/workflows/deploy.yml | 47 ++++++++++++++++++++++++++++++++++++ package-lock.json | 10 ++++++++ package.json | 1 + src/routes/+layout.ts | 1 + static/.nojekyll | 0 svelte.config.js | 15 ++++++++---- 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/deploy.yml create mode 100644 src/routes/+layout.ts create mode 100644 static/.nojekyll diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..491e2a2 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,47 @@ +name: Deploy to GitHub Pages +on: + push: + branches: 'main' + +jobs: + build_site: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm install + + - name: build + env: + BASE_PATH: '/${{ github.event.repository.name }}' + run: | + npm run build + + - name: Upload Artifacts + uses: actions/upload-pages-artifact@v3 + with: + # this should match the `pages` option in your adapter-static options + path: 'build/' + + deploy: + needs: build_site + runs-on: ubuntu-latest + + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy + id: deployment + uses: actions/deploy-pages@v4 diff --git a/package-lock.json b/package-lock.json index 3ba7aca..373b7b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,6 +19,7 @@ "@skeletonlabs/skeleton": "2.10.1", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-static": "^3.0.2", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@tailwindcss/forms": "0.5.7", @@ -1005,6 +1006,15 @@ "@sveltejs/kit": "^2.0.0" } }, + "node_modules/@sveltejs/adapter-static": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@sveltejs/adapter-static/-/adapter-static-3.0.2.tgz", + "integrity": "sha512-/EBFydZDwfwFfFEuF1vzUseBoRziwKP7AoHAwv+Ot3M084sE/HTVBHf9mCmXfdM9ijprY5YEugZjleflncX5fQ==", + "dev": true, + "peerDependencies": { + "@sveltejs/kit": "^2.0.0" + } + }, "node_modules/@sveltejs/kit": { "version": "2.5.18", "resolved": "https://registry.npmjs.org/@sveltejs/kit/-/kit-2.5.18.tgz", diff --git a/package.json b/package.json index 9e5ec4b..82cc71f 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "@skeletonlabs/skeleton": "2.10.1", "@skeletonlabs/tw-plugin": "0.4.0", "@sveltejs/adapter-auto": "^3.0.0", + "@sveltejs/adapter-static": "^3.0.2", "@sveltejs/kit": "^2.0.0", "@sveltejs/vite-plugin-svelte": "^3.0.0", "@tailwindcss/forms": "0.5.7", diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts new file mode 100644 index 0000000..189f71e --- /dev/null +++ b/src/routes/+layout.ts @@ -0,0 +1 @@ +export const prerender = true; diff --git a/static/.nojekyll b/static/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/svelte.config.js b/svelte.config.js index f81a659..6582f43 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -1,21 +1,26 @@ -import adapter from '@sveltejs/adapter-auto'; +import adapter from '@sveltejs/adapter-static'; import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; +const dev = process.argv.includes('dev'); + /** @type {import('@sveltejs/kit').Config} */ const config = { extensions: ['.svelte'], // Consult https://kit.svelte.dev/docs/integrations#preprocessors // for more information about preprocessors preprocess: [vitePreprocess()], - + vitePlugin: { - inspector: true, + inspector: true }, kit: { // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. // If your environment is not supported or you settled on a specific environment, switch out the adapter. // See https://kit.svelte.dev/docs/adapters for more information about adapters. - adapter: adapter() + adapter: adapter(), + paths: { + base: dev ? '' : process.env.BASE_PATH + } } }; -export default config; \ No newline at end of file +export default config;