Please update the Github Pages deployment wiki
See original GitHub issueThis 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:
- Created 4 years ago
- Reactions:3
- Comments:12 (6 by maintainers)
It seems the deployment instructions for Github Pages were now completely removed, there’s nothing in the NextJS docs site about it?
Where did the instructions for Github Pages go!