Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Heroku Buildpack for create-react-app: static hosting for React.js web apps

License

NotificationsYou must be signed in to change notification settings

FJF616/create-react-app-buildpack

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.


Requires

Usage

Generate a React app

create-react-app my-appcd 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 topush 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 theapp name & its URLhttps://my-app-name.herokuapp.com
  • sets thebuildpack to deploy acreate-react-app app
  • configures theheroku remote in the local git repo, sogit 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 onyour dashboard.

Continue Development

Work with your app locally usingnpm 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 topush an existing repository from the command line.

Customization

Web server

The web server may beconfigured via the static buildpack.

The defaultstatic.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 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"  }}

HTTPS-only

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-age is the number of seconds to enforce HTTPS since the last connection; the example is 90-days

Environment variables

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 master

Version compatibility

This 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.

Architecture 🏙

This buildpack composes three buildpacks (specified in.buildpacks) to supportno-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 thedefaultstatic.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 tocreate-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 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

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript89.5%
  • CSS6.3%
  • Shell4.2%

[8]ページ先頭

©2009-2025 Movatter.jp