Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

mars/create-react-app-buildpack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Heroku Buildpack for create-react-app

Deploy React.js web apps generated with create-react-app. Automates deployment with the built-in bundler and serves it up via Nginx. See the introductory blog post and entry in Heroku elements.


Requires

Usage

Generate a React app

create-react-app my-app
cd my-app

Make it a git repo

git init

At this point, this new repo is local, only on your computer. Eventually, you may want to push to Github.

Create the Heroku app

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 the app name & its URL https://my-app-name.herokuapp.com
  • sets the buildpack to deploy a create-react-app app
  • configures the heroku remote in the local git repo, so git push heroku master will push to this new Heroku app.

Commit & deploy ♻️

git add .
git commit -m "react-create-app on Heroku"
git push heroku master

Visit the app's public URL in your browser

heroku open

Visit the Heroku Dashboard for the app

Find the app on your dashboard.

Continue Development

Work with your app locally using npm start. See: create-react-app docs

Then, commit & deploy ♻️

Push to Github

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 to push an existing repository from the command line.

Customization

Web server

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/" }

Routing clean URLs

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"
  }
}

HTTPS-only

Enforce secure connections by automatically redirecting insecure requests to https://, in static.json:

{
  "https_only": true
}

Prevent downgrade attacks with HTTP strict transport security. Add HSTS "headers" to static.json:

{
  "headers": {
    "/**": {
      "Strict-Transport-Security": "max-age=7776000"
    }
  }
}
  • max-age is the number of seconds to enforce HTTPS since the last connection; the example is 90-days

Environment variables

REACT_APP_* and NODE_* environment variables are supported on Heroku during the compile phase, when npm run build is executed to generate the JavaScript bundle.

Set config 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 master

Version compatibility

This buildpack will never intentionally cause previously deployed apps to become undeployable. Using master as 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

✏️ Replace v1.2.1 with the desired release tag.

♻️ Then, commit & deploy to rebuild on the new buildpack version.

Architecture 🏙

This buildpack composes three buildpacks (specified in .buildpacks) to support no-configuration deployment on Heroku:

  1. heroku/nodejs buildpack
  • complete Node.js enviroment to support the webpack build
  • node_modules cached between deployments
  1. mars/create-react-app-inner-buildpack
  • generates the default static.json
  • performs the production build for create-react-app, npm run build
  1. heroku/static buildpack

General-purpose SPA deployment

Some kind feedback pointed out that this buildpack is not necessarily specific to create-react-app.

This buildpack can deploy any SPA [single-page app] as long as it meets the following requirements:

Development

Build Status

Create & run tests using the Buildpack 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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy