Deploy React.js web apps generated with create-react-app.
Automates deployment with the built-in tooling and serves it up via Nginx.
- Heroku
- git
- Node.js
- create-react-app
npm install -g create-react-app
create-react-app my-app
cd my-app
git init
heroku create -b https://github.com/mars/create-react-app-buildpack.git
git add .
git commit -m "react-create-app on Heroku"
git push heroku master
heroku open
heroku browse
Work with your app locally using npm start
. See: create-react-app docs
Then, commit & deploy ♻️
The web server may be configured via the static buildpack.
The default static.json
, if it does not exist in the repo, is:
{ "root": "build/" }
By default, React Router (not included) uses hash-based URLs like https://example.com/index.html#/users/me/edit
. This is nice & easy when getting started with local development, but for a public app you probably want real URLs like https://example.com/users/me/edit
.
Create a static.json
file to configure the web server for clean browserHistory
URLs with React Router:
{
"root": "build/",
"clean_urls": false,
"routes": {
"/**": "index.html"
}
}
This buildpack composes three buildpacks (specified in .buildpacks
) to support no-configuration deployment on Heroku:
- complete Node.js enviroment to support the webpack build
node_modules
cached between deployments
- generates the default
static.json
- performs the production build for create-react-app,
npm run build
- Nginx web server
- handy static website & SPA (single-page app) customization options