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

Commit 0c5aa4d

Browse files
committed
Move bundling to runtime; fix for stateless builds
1 parent 1f5369b commit 0c5aa4d

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

.buildpacks

+1-1
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#v1.3.0
2+
https://github.com/mars/create-react-app-inner-buildpack.git#stateless-build
33
https://github.com/heroku/heroku-buildpack-static.git

.profile.d/create-react-app.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
3+
# Fail immediately on non-zero exit code.
4+
set -e
5+
6+
# Build the javascript bundle.
7+
# Performed at runtime to pickup current `REACT_APP_*` environment variables.
8+
/app/.heroku/node/bin/npm run build

README.md

+11-4
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,19 @@ Set [config vars on a Heroku app](https://devcenter.heroku.com/articles/config-v
116116
heroku config:set REACT_APP_HELLO='I love sushi!'
117117
```
118118

119-
♻️ 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.
119+
#### Add-on config vars
120+
121+
To use the config vars directly from an add-on, create it with a custom `REACT_APP_` prefix.
122+
123+
Example with the `fixie` add-on:
120124

121125
```bash
122-
git commit --allow-empty -m "Set REACT_APP_HELLO config var"
123-
git push heroku master
126+
heroku addons:create fixie --as REACT_APP_FIXIE
124127
```
125128

129+
See: [Creating an add-on](https://devcenter.heroku.com/articles/managing-add-ons#creating-an-add-on)
130+
131+
126132
Version compatibility
127133
---------------------
128134

@@ -147,11 +153,12 @@ This buildpack composes three buildpacks (specified in [`.buildpacks`](.buildpac
147153
* `node_modules` cached between deployments
148154
2. [`mars/create-react-app-inner-buildpack`](https://github.com/mars/create-react-app-inner-buildpack)
149155
* generates the [default `static.json`](#customization)
150-
* performs the production build for create-react-app, `npm run build`
151156
3. [`heroku/static` buildpack](https://github.com/heroku/heroku-buildpack-static)
152157
* [Nginx](http://nginx.org/en/) web server
153158
* handy static website & SPA (single-page app) [customization options](https://github.com/heroku/heroku-buildpack-static#configuration)
154159

160+
Whenever a [dyno](https://devcenter.heroku.com/articles/dynos) starts-up, [`npm run build` is executed](.profile.d/create-react-app.sh) to create the production bundle with the current [environment variables](#environment-variables).
161+
155162

156163
### General-purpose SPA deployment
157164

bin/compile

+4
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,7 @@ else
6464
echo "create-react-app `.buildpacks` not defined. Exiting."
6565
exit 1
6666
fi
67+
68+
echo '=====> Enabling `npm run build` on start-up'
69+
mkdir -p $BUILD_DIR/.profile.d
70+
cp $BP_DIR/.profile.d/create-react-app.sh $BUILD_DIR/.profile.d/

0 commit comments

Comments
 (0)