|
1 | | -# Next.js GitHub Pages |
| 1 | +# Bookmarks |
2 | 2 |
|
3 | | -Deploy Next.js to GitHub Pages with GitHub Actions. [View the deployed app](https://gregrickaby.github.io/nextjs-github-pages/) 🚀 |
| 3 | +via Raindrops, Next.js, GitHub Pages, and written in Code Spaces |
4 | 4 |
|
5 | | -> ⚠️ Heads up! GitHub Pages _does not_ support serverless or edge functions. This means dynamic functionality will be disabled. See all the [unsupported features](https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features). |
6 | | -
|
7 | | ---- |
8 | | - |
9 | | -## Configure Next.js |
10 | | - |
11 | | -### Next.js Config |
12 | | - |
13 | | -First, you need to configure Next.js to [deploy static exports](https://nextjs.org/docs/app/building-your-application/deploying/static-exports). This is required for GitHub Pages to work. |
14 | | - |
15 | | -1. Open the `next.config.ts` file |
16 | | -2. Add the following: |
17 | | - |
18 | | -```typescript |
19 | | -import type { NextConfig } from "next"; |
20 | | - |
21 | | -const nextConfig: NextConfig = { |
22 | | - /** |
23 | | - * Enable static exports. |
24 | | - * |
25 | | - * @see https://nextjs.org/docs/app/building-your-application/deploying/static-exports |
26 | | - */ |
27 | | - output: "export", |
28 | | - |
29 | | - /** |
30 | | - * Set base path. This is the slug of your GitHub repository. |
31 | | - * |
32 | | - * @see https://nextjs.org/docs/app/api-reference/next-config-js/basePath |
33 | | - */ |
34 | | - basePath: "/nextjs-github-pages", |
35 | | - |
36 | | - /** |
37 | | - * Disable server-based image optimization. Next.js does not support |
38 | | - * dynamic features with static exports. |
39 | | - * |
40 | | - * @see https://nextjs.org/docs/app/api-reference/components/image#unoptimized |
41 | | - */ |
42 | | - images: { |
43 | | - unoptimized: true, |
44 | | - }, |
45 | | -}; |
46 | | - |
47 | | -export default nextConfig; |
48 | | -``` |
49 | | - |
50 | | -3. Save the `next.config.ts` |
51 | | - |
52 | | -4. Finally, place a `.nojekyll` file in the `/public` directory to disable GitHub Pages from trying to create a [Jekyll](https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/) website. |
| 5 | +Based on [nextjs-github-pages](https://github.com/gregrickaby/nextjs-github-pages) |
53 | 6 |
|
54 | | -```treeview |
55 | | -. |
56 | | -├── app/ |
57 | | -├── public/ |
58 | | -│ └── .nojekyll |
59 | | -├── next.config.ts |
60 | | -``` |
61 | | - |
62 | | -Perfect! This is all you need to configure Next.js to deploy on GitHub Pages. |
| 7 | +## Links |
| 8 | +- [repo](https://github.com/seeReadCode/bookmarks) |
| 9 | +- [codespace dev](https://shiny-lamp-wpjpj5q7vj3ggw9.github.dev/) |
| 10 | +- [codespace admin](https://github.com/codespaces?repository_id=1036822786) |
63 | 11 |
|
64 | | -### Add base path to `page.tsx` |
65 | 12 |
|
66 | | -Next, you will need to add the base path to images in `page.tsx` file. This is required for the images to appear on GitHub Pages. |
| 13 | +## Docs |
67 | 14 |
|
68 | | -1. Open `app/page.tsx` |
69 | | -2. Find the `Image` components |
70 | | -3. Add `/nextjs-github-pages/` (or the slug of your GitHub repository) to the `src` prop: |
71 | | - |
72 | | -```tsx |
73 | | -<Image |
74 | | - src="/nextjs-github-pages/vercel.svg" |
75 | | - alt="Vercel Logo" |
76 | | - className={styles.vercelLogo} |
77 | | - width={100} |
78 | | - height={24} |
79 | | - priority |
80 | | -/> |
81 | | -``` |
82 | 15 |
|
83 | | -4. Save the `page.tsx` file |
84 | | - |
85 | | -Learn more by reading the official documentation [for basePath and images](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath#images). |
| 16 | +> ⚠️ Heads up! GitHub Pages _does not_ support serverless or edge functions. This means dynamic functionality will be disabled. See all the [unsupported features](https://nextjs.org/docs/app/building-your-application/deploying/static-exports#unsupported-features). |
86 | 17 |
|
87 | 18 | --- |
| 19 | +## TODO |
| 20 | +- deploy.yml (from cloned repo) v. alt from github.com |
| 21 | +- fix build |
88 | 22 |
|
89 | | -## Configure GitHub Repository |
90 | | - |
91 | | -Now that Next.js is configured, you need to set up your GitHub repository to deploy to GitHub Pages. |
| 23 | +## Changelog |
92 | 24 |
|
93 | | -### Setup GitHub Action |
| 25 | +- Enabled Github Pages on github.com via suggested Next.js config |
| 26 | +- Replaced `next-js-github-pages` |
| 27 | +- Set env variables via github.com and tested in Codespace console |
94 | 28 |
|
95 | | -This is where the magic happens! This [workflow file](https://github.com/gregrickaby/nextjs-github-pages/blob/main/.github/workflows/deploy.yml) will automatically build and deploy the app when you push to the `main` branch. |
96 | 29 |
|
97 | | -1. Create `.github/workflows/deploy.yml` file |
98 | | -2. Paste the contents of <https://github.com/gregrickaby/nextjs-github-pages/blob/main/.github/workflows/deploy.yml> |
99 | | -3. Save the `deploy.yml` file |
100 | 30 |
|
101 | 31 | ### Enable GitHub Pages |
102 | 32 |
|
|
0 commit comments