Skip to content

Commit d835416

Browse files
committed
docs(github-pages): Improve doc on github-pages deployment
- Add hint to use GitHub Actions GITHUB_REPOSITORY variable - Add paragraph how to get favicons working on a GitHub Pages deployment closes #1776
1 parent e5e4558 commit d835416

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

content/3.deploy/github-pages.md

+57-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,20 @@ GitHub Pages only support static sites, Nuxt will pre-render your application to
1515

1616
::caution
1717
If you are **not** using a custom domain, you need to set `NUXT_APP_BASE_URL` to your repository-slug for your build step.
18-
18+
:br
1919
**Example**: `https://<user>.github.io/<repository>/`: `NUXT_APP_BASE_URL=/<repository>/ npx nuxt build --preset github_pages`
2020
::
2121

22+
::tip
23+
**Zero Configuration ✨**
24+
:br
25+
In a **GitHub Workflow** you can make use of the pre-defined env var `GITHUB_REPOSITORY`: `NUXT_APP_BASE_URL="/${GITHUB_REPOSITORY##*/}/" npx nuxt build --preset github_pages`
26+
::
27+
28+
::read-more{to="https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/accessing-contextual-information-about-workflow-runs#github-context" target="_blank"}
29+
Head over **GitHub Actions Context** to learn more about the GitHub Actions context variables.
30+
::
31+
2232
## Setup
2333

2434
Follow the steps to [create a GitHub Pages site](https://docs.github.com/en/pages/getting-started-with-github-pages/creating-a-github-pages-site).
@@ -46,7 +56,8 @@ jobs:
4656
node-version: "20"
4757
# Pick your own package manager and build script
4858
- run: npm install
49-
- run: npx nuxt build --preset github_pages
59+
# Use NUXT_APP_BASE_URL="" if your GitHub Pages is configured for a custom domain
60+
- run: NUXT_APP_BASE_URL="/${GITHUB_REPOSITORY##*/}/" npx nuxt build --preset github_pages
5061
- name: Upload artifact
5162
uses: actions/upload-pages-artifact@v3
5263
with:
@@ -74,3 +85,47 @@ jobs:
7485
::read-more{to="https://nitro.unjs.io/deploy/providers/github-pages" target="_blank"}
7586
Head over **Nitro documentation** to learn more about the github-pages deployment preset.
7687
::
88+
89+
## Favicons
90+
91+
Favicons typically are expected at hosting domain root. In case of a GitHub Pages deployment this does not work.
92+
93+
For this reason favicon URLs should be defined for the pages header starting with the GitHub Pages base URL as absolute path to work for a single page app as well as for a multi-route app.
94+
95+
::note
96+
Favicon files should be maintained within the projects `public/` folder.
97+
::
98+
99+
**Example:** If you have `public/favicon.ico` and `public/favicon-16x16.png` your `nuxt.config.ts` should start as follows:
100+
```ts [nuxt.config.ts]
101+
// Make use of compile time environment var NUXT_APP_BASE_URL
102+
// to make baseURL work for GitHub Pages deployments as well.
103+
// See https://vite.dev/guide/env-and-mode.html for details.
104+
const baseURL = import.meta.env.NUXT_APP_BASE_URL
105+
? import.meta.env.NUXT_APP_BASE_URL
106+
: "/";
107+
// https://nuxt.com/docs/api/configuration/nuxt-config
108+
export default defineNuxtConfig({
109+
app: {
110+
head: {
111+
title: "My Nuxt App",
112+
link: [
113+
{
114+
rel: "icon",
115+
type: "image/x-icon",
116+
href: baseURL + "favicon.ico?x=2",
117+
},
118+
{
119+
rel: "icon",
120+
type: "image/png",
121+
sizes: "16x16",
122+
href: baseURL + "favicon-16x16.png",
123+
},
124+
// Add more favicons if wanted ...
125+
],
126+
},
127+
// probale other app content ...
128+
},
129+
// other config ...
130+
)};
131+
```

0 commit comments

Comments
 (0)