question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Please update the Github Pages deployment wiki

See original GitHub issue

This page: https://github.com/zeit/next.js/wiki/Deploying-a-Next.js-app-into-GitHub-Pages

Should include the following:

For all sites

Create next.config.js in your main folder with the following:

module.exports = {
  generateBuildId: async () => 'current',
};

This will prevent next from generating a new version of the site every time you run build. This is helpful since you’ll likely be pushing out folder to your source gh-pages branch (see below).

For Project Page Sites

Fix your links by adding the following component to components/:

import Link from 'next/link'

// Fixes links by prepending linkPrefix when in deployed on Github
const PrefixedLink = ({ href, as = href, children }) => (
  <Link href={href} as={`${process.env.linkPrefix}${as}`}>
    {children}
  </Link>
)

export default PrefixedLink

And replace all import Link from 'next/link' in your code with import Link from 'next/link'

And use the following next.config.js:

const repoNameURIPrefix =
  process.env.NODE_ENV === 'production' ? '/your-repo-name' : '';

module.exports = {
  assetPrefix: repoNameURIPrefix,
  env: {
    linkPrefix: repoNameURIPrefix,
  },
  generateBuildId: async () => 'current',
};

Don’t forget to replace your-repo-name with the actual name of your Github repository.

Pushing to GitHub Pages from a Subdirectory

In your next folder run something like:

git add out
git commit -m "Added built website"

To add the output folder and commit it. Then push it (from the root of your repo) to gh-pages branch:

git subtree push --prefix out origin gh-pages

If your next folder isn’t at the root of your repo, you might need to replace out with the path to the out folder from the root of your repo (ie next-website/out).

See https://gist.github.com/cobyism/4730490 for more details.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
tommoorcommented, Jun 13, 2020

It seems the deployment instructions for Github Pages were now completely removed, there’s nothing in the NextJS docs site about it?

1reaction
bymoecommented, Jun 15, 2020

Where did the instructions for Github Pages go!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding or editing wiki pages - GitHub Docs
You can add and edit wiki pages directly on GitHub or locally using the command line. ... Using the wiki sidebar, navigate to...
Read more >
Deploy wiki to new gh-pages branch · Issue #188 - GitHub
We are considering using the wiki instead of developing the documentation on the master branch. However, we still want to have a nice ......
Read more >
About GitHub Pages
GitHub Pages is a static site hosting service that takes HTML, CSS, and JavaScript files straight from a repository on GitHub, optionally runs...
Read more >
Marketplace Actions Deploy to GitHub Pages
Automatically deploy your project to GitHub Pages with GitHub Actions. This action can be configured to push your production-ready code into any branch ......
Read more >
need help deploying to gh-pages · Issue #381 - GitHub
I am build json schema into README docs using jsonschema2md and it is working, but I am unable to deploy pages.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found