Deploy Next.js universal web apps on Heroku.
Demo deployment from this repo:
https://nextjs.herokuapp.com
Download this repo as a Heroku-ready app template, or follow Production Deployment to push an existing app to Heroku.
Once you have a Next.js app working locally, you may deploy it for public access.
✏️ In the following instructions, replace $my-app-name
with your own unique app name.
- Install the Heroku build adapter:
npm install @mars/heroku-nextjs-build --save
- Merge the following entries into
package.json
:
{
"scripts": {
"start": "next start -p $PORT",
"postinstall": "heroku-nextjs-build"
},
"engines": {
"node": "6.9.1"
},
"cacheDirectories": [
"nextjs/node_modules"
]
}
- Ensure the app is a git repo, ignoring local-only directories:
git init
(echo node_modules/ && echo .next/) >> .gitignore
- Create the Heroku app:
heroku create $my-app-name
- 🚀 Deploy:
git add .
git commit -m 'Next.js app on Heroku'
git push heroku master
- ♻️ Deploy changes: add, commit, & push again.