Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 16e6ec7

Browse files
authored
Support dyno metadata during build (mars#129)
1 parent afe3b08 commit 16e6ec7

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

.buildpacks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
https://github.com/heroku/heroku-buildpack-nodejs.git
2-
https://github.com/mars/create-react-app-inner-buildpack.git#v5.1.0
2+
https://github.com/mars/create-react-app-inner-buildpack.git#v6.0.0
33
https://github.com/heroku/heroku-buildpack-static.git

README.md

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ Replace `http://localhost:8000` with the URL to your local or remote backend ser
311311

312312
### Environment variables
313313

314-
[`REACT_APP_*` environment variables](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables) are supported with this buildpack.
314+
[`REACT_APP_*` environment variables](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables) are fully supported with this buildpack.
315315

316-
🤐 *Be careful not to export secrets. These values may be accessed by anyone who can see the React app.*
316+
🚫🤐 ***Not for secrets.** These values may be accessed by anyone who can see the React app.*
317317

318318
### [Set vars on Heroku](https://devcenter.heroku.com/articles/config-vars)
319319

@@ -349,7 +349,23 @@ ex: `REACT_APP_FILEPICKER_API_KEY` ([Add-on config vars](#user-content-add-on-co
349349

350350
### Compile-time configuration
351351

352-
♻️ The app must be re-deployed for compiled changes to take effect.
352+
Supports [`REACT_APP_`](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables), `NODE_`, `NPM_`, & `HEROKU_` prefixed variables.
353+
354+
Use Node's [`process.env` object](https://nodejs.org/dist/latest-v10.x/docs/api/process.html#process_process_env).
355+
356+
```javascript
357+
import React, { Component } from 'react';
358+
359+
class App extends Component {
360+
render() {
361+
return (
362+
<code>Runtime env var example: { process.env.REACT_APP_HELLO }</code>
363+
);
364+
}
365+
}
366+
```
367+
368+
♻️ The app must be re-deployed for compiled changes to take effect, because during the build, these references will be replaced with their quoted string value.
353369

354370
```bash
355371
heroku config:set REACT_APP_HELLO='I love sushi!'
@@ -358,9 +374,17 @@ git commit --allow-empty -m "Set REACT_APP_HELLO config var"
358374
git push heroku master
359375
```
360376

377+
Only `REACT_APP_` vars are replaced in create-react-app's build. To make any other variables visible to React, they must be prefixed for the build command in `package.json`, like this:
378+
379+
```bash
380+
REACT_APP_HEROKU_SLUG_COMMIT=$HEROKU_SLUG_COMMIT react-scripts build
381+
```
382+
361383
### Runtime configuration
362384

363-
*Requires at least create-react-app 0.7.*
385+
Supports only [`REACT_APP_`](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables) prefixed variables.
386+
387+
🚫🤐 ***Not for secrets.** These values may be accessed by anyone who can see the React app.*
364388

365389
Install the [runtime env npm package](https://www.npmjs.com/package/@mars/heroku-js-runtime-env):
366390

@@ -407,9 +431,9 @@ heroku config:unset JS_RUNTIME_TARGET_BUNDLE
407431

408432
### Add-on config vars
409433

410-
🤐 *Be careful not to export secrets. These values may be accessed by anyone who can see the React app.*
434+
🚫🤐 ***Be careful not to export secrets.** These values may be accessed by anyone who can see the React app.*
411435

412-
Use a custom [`.profile.d` script](https://devcenter.heroku.com/articles/buildpack-api#profile-d-scripts) to make variables visible to the React app by prefixing them with `REACT_APP_`.
436+
Use a custom [`.profile.d` script](https://devcenter.heroku.com/articles/buildpack-api#profile-d-scripts) to make variables set by other components available to the React app by prefixing them with `REACT_APP_`.
413437

414438
1. create `.profile.d/000-react-app-exports.sh`
415439
1. make it executable `chmod +x .profile.d/000-react-app-exports.sh`
@@ -476,10 +500,10 @@ This buildpack will never intentionally cause previously deployed apps to become
476500
[Releases are tagged](https://github.com/mars/create-react-app-buildpack/releases), so you can lock an app to a specific version, if that kind of determinism pleases you:
477501

478502
```bash
479-
heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#v5.1.0
503+
heroku buildpacks:set https://github.com/mars/create-react-app-buildpack.git#v6.0.0
480504
```
481505

482-
✏️ *Replace `v5.1.0` with the desired [release tag](https://github.com/mars/create-react-app-buildpack/releases).*
506+
✏️ *Replace `v6.0.0` with the desired [release tag](https://github.com/mars/create-react-app-buildpack/releases).*
483507

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

@@ -500,7 +524,7 @@ This buildpack combines several buildpacks, specified in [`.buildpacks`](.buildp
500524
2. [`mars/create-react-app-inner-buildpack`](https://github.com/mars/create-react-app-inner-buildpack)
501525
* production build for create-react-app
502526
* executes the npm package's build script; create-react-app default is `react-scripts build`
503-
* exposes `REACT_APP_`, `NODE_`, & `NPM_` prefixed env vars to the build script
527+
* exposes `REACT_APP_`, `NODE_`, `NPM_`, & `HEROKU_` prefixed env vars to the build script
504528
* generates a production bundle regardless of `NODE_ENV` setting
505529
* sets default [web server config](#user-content-web-server) unless `static.json` already exists
506530
* enables [runtime environment variables](#user-content-environment-variables)

0 commit comments

Comments
 (0)