Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GitHub Pages deployment example. #37282

Merged
merged 3 commits into from
May 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions examples/gh-pages/.babelrc.js

This file was deleted.

45 changes: 0 additions & 45 deletions examples/gh-pages/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions examples/gh-pages/env-config.js

This file was deleted.

9 changes: 0 additions & 9 deletions examples/gh-pages/next.config.js

This file was deleted.

20 changes: 0 additions & 20 deletions examples/gh-pages/package.json

This file was deleted.

14 changes: 0 additions & 14 deletions examples/gh-pages/pages/about.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/gh-pages/pages/index.js

This file was deleted.

File renamed without changes.
31 changes: 31 additions & 0 deletions examples/github-pages/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Deploying to GitHub Pages

This example supports deloying a static Next.js application (using `next export`) to GitHub Pages.

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init), [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/), or [pnpm](https://pnpm.io) to bootstrap the example:

```bash
npx create-next-app --example github-pages nextjs-github-pages
# or
yarn create next-app --example github-pages nextjs-github-pages
# or
pnpm create next-app --example github-pages nextjs-github-pages
```

### Deploy to GitHub Pages

1. Create a new public GitHub repository.
1. Edit `next.config.js` to match your GitHub repository name.
1. Push the starter code to the `main` branch.
1. Run the `deploy` script (e.g. `npm run deploy`) to create the `gh-pages` branch.
1. On GitHub, go to **Settings** > **Pages** > **Source**, and choose `gh-pages` as the branch with the `/root` folder. Hit **Save**.
1. Make a change.
1. Run the `deploy` script again to push the changes to GitHub Pages.

Congratulations! You should have a URL like:

```bash
https://<github-user-name>.github.io/<github-project-name>/
```
3 changes: 3 additions & 0 deletions examples/github-pages/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
basePath: '/gh-pages-test',
}
13 changes: 13 additions & 0 deletions examples/github-pages/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"scripts": {
"dev": "next",
"build": "next build && next export",
"deploy": "next build && touch out/.nojekyll && git add out/ && git commit -m \"Deploy\" && git subtree push --prefix out origin gh-pages"
},
"dependencies": {
"next": "latest",
"react": "latest",
"react-dom": "latest"
}
}
12 changes: 12 additions & 0 deletions examples/github-pages/pages/about.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Link from 'next/link'

export default function About() {
return (
<div>
<div>About</div>
<div>
Back to <Link href="/">Home</Link>
</div>
</div>
)
}
9 changes: 9 additions & 0 deletions examples/github-pages/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Link from 'next/link'

export default function Home() {
return (
<div>
Hello World. <Link href="/about">About</Link>
</div>
)
}