- Notifications
You must be signed in to change notification settings - Fork0
Heroku Buildpack for create-react-app: static hosting for React.js web apps
License
FJF616/create-react-app-buildpack
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Deploy React.js web apps generated withcreate-react-app. Automates deployment with the built-in bundler and serves it up viaNginx. See theintroductory blog post and entry inHeroku elements.
- Heroku
- git
- Node.js
- create-react-app
npm install -g create-react-app
create-react-app my-appcd my-appgit init
At this point, this new repo is local, only on your computer. Eventually, you may want topush to Github.
heroku create$my-app-name --buildpack https://github.com/mars/create-react-app-buildpack.git✏️Replace$my-app-name with a name for your unique app.
This command:
- sets theapp name & its URL
https://my-app-name.herokuapp.com - sets thebuildpack to deploy a
create-react-appapp - configures the
herokuremote in the local git repo, sogit push heroku masterwill push to this new Heroku app.
git add.git commit -m"react-create-app on Heroku"git push heroku master
heroku open
Find the app onyour dashboard.
Work with your app locally usingnpm start. See:create-react-app docs
Then, commit & deploy ♻️
Eventually, to share, collaborate, or simply back-up your code,create an empty repo at Github, and then follow the instructions shown on the repo topush an existing repository from the command line.
The web server may beconfigured via the static buildpack.
The defaultstatic.json, if it does not exist in the repo, is:
{"root":"build/" }By default,React Router (not included) uses hash-based URLs likehttps://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 likehttps://example.com/users/me/edit.
Create astatic.json file to configure the web server for cleanbrowserHistory URLs with React Router:
{"root":"build/","clean_urls":false,"routes": {"/**":"index.html" }}Enforce secure connections by automatically redirecting insecure requests tohttps://, instatic.json:
{"https_only":true}Prevent downgrade attacks withHTTP strict transport security. Add HSTS"headers" tostatic.json:
{"headers": {"/**": {"Strict-Transport-Security":"max-age=7776000" } }}max-ageis the number of seconds to enforce HTTPS since the last connection; the example is 90-days
REACT_APP_* andNODE_* environment variables are supported on Heroku during the compile phase, whennpm run build is executed to generate the JavaScript bundle.
Setconfig vars on a Heroku app like this:
heroku config:set REACT_APP_HELLO='I love sushi!'♻️ The app must be re-deployed for this change to take effect, because the automatic restart after a config var change does not rebuild the JavaScript bundle.
git commit --allow-empty -m"Set REACT_APP_HELLO config var"git push heroku masterThis buildpack will never intentionally cause previously deployed apps to become undeployable. Using masteras directed in the main instructions will always deploy an app with the most recent version of this buildpack.
Releases are tagged, so you can lock an app to a specific version, if that kind of determinism pleases you:
heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#v1.2.1
✏️Replacev1.2.1 with the desiredrelease tag.
♻️ Then, commit & deploy to rebuild on the new buildpack version.
This buildpack composes three buildpacks (specified in.buildpacks) to supportno-configuration deployment on Heroku:
- complete Node.js enviroment to support the webpack build
node_modulescached between deployments
- generates thedefault
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
Some kind feedback pointed out that this buildpack is not necessarily specific tocreate-react-app.
This buildpack can deploy any SPA [single-page app] as long as it meets the following requirements:
npm run buildperforms the transpile/bundling- the file
build/index.htmlorthe root specified instatic.jsonexists at runtime.
Create & run tests using theBuildpack Testrunner. See the local setup guide.
Open issues with ideas about feature direction.
About
Heroku Buildpack for create-react-app: static hosting for React.js web apps
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- JavaScript89.5%
- CSS6.3%
- Shell4.2%