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

Commit

Permalink
Deploy with auto build (#156)
Browse files Browse the repository at this point in the history
* Use Node buildpack‘s auto build

* Remove NODE_ENV=development workaround since Node buildpack installs devDeps for build & auto-runs build.

* 📚 link to Dev Center for Node.js build customization

* Switch to new Node auto build behavior ahead of release

* Upgrade to "Node auto build" release version of inner buildpack
  • Loading branch information
mars committed Mar 11, 2019
1 parent 1b64ebf commit 411505b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .buildpacks
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
https://github.com/heroku/heroku-buildpack-nodejs.git
https://github.com/mars/create-react-app-inner-buildpack.git#v8.0.0
https://github.com/mars/create-react-app-inner-buildpack.git#v9.0.0
https://github.com/heroku/heroku-buildpack-static.git
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ ex: `REACT_APP_FILEPICKER_API_KEY` ([Add-on config vars](#user-content-add-on-co

### Compile-time configuration

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.
Supports all config vars, including [`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.

☝️🤐 ***Use secrets carefully.** If these values are embedded in the JavaScript bundle, like with `REACT_APP_` vars, then they may be accessed by anyone who can see the React app.*

Use Node's [`process.env` object](https://nodejs.org/dist/latest-v10.x/docs/api/process.html#process_process_env).

Expand Down Expand Up @@ -528,15 +530,12 @@ This buildpack combines several buildpacks, specified in [`.buildpacks`](.buildp
* installs `node`, puts on the `$PATH`
* version specified in [`package.json`, `engines.node`](https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version)
* `node_modules/` cached between deployments
* `NODE_ENV` at buildtime:
* defaults to `NODE_ENV=development` to install the build tooling of create-react-app's dev dependencies, like `react-scripts`
* honors specific setting of `NODE_ENV`, like `NODE_ENV=test` for [automated testing](#user-content-testing) in [`bin/test`](bin/test-compile)
* but forces `NODE_ENV=production` to be `development` to ensure dev dependencies are available for build
2. [`mars/create-react-app-inner-buildpack`](https://github.com/mars/create-react-app-inner-buildpack)
* production build for create-react-app
* executes the npm package's build script; create-react-app default is `react-scripts build`
* exposes `REACT_APP_`, `NODE_`, `NPM_`, & `HEROKU_` prefixed env vars to the build script
* [executes the npm package's build script](https://devcenter.heroku.com/changelog-items/1557); create-react-app default is `react-scripts build`
* exposes all env vars to the build script
* generates a production bundle regardless of `NODE_ENV` setting
* customize further with [Node.js build configuration](https://devcenter.heroku.com/articles/nodejs-support#customizing-the-build-process)
2. [`mars/create-react-app-inner-buildpack`](https://github.com/mars/create-react-app-inner-buildpack)
* sets default [web server config](#user-content-web-server) unless `static.json` already exists
* enables [runtime environment variables](#user-content-environment-variables)
3. [`heroku/static` buildpack](https://github.com/heroku/heroku-buildpack-static)
Expand Down
18 changes: 3 additions & 15 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ CACHE_DIR=$2
ENV_DIR=$3
BP_DIR=`cd $(dirname $0); cd ..; pwd`

# Switch to new Node auto build behavior ahead of release
export NEW_BUILD_SCRIPT_BEHAVIOR=true

# Use architecture of multi-buildpack to compose behavior.
# https://github.com/heroku/heroku-buildpack-multi
cp $BP_DIR/.buildpacks $BUILD_DIR/.buildpacks
Expand All @@ -31,21 +34,6 @@ branch=""
dir=$(mktemp -t buildpackXXXXX)
rm -rf $dir

echo "-----> Configure create-react-app build environment"
# Set env vars for the inner buildpacks in `.buildpacks`
# * during compile, install build tooling (devDependencies) with npm & Yarn
# * in runtime, NODE_ENV is not used (this buildpack launches a static web server)
export NPM_CONFIG_PRODUCTION=false
INHERITED_NODE_ENV="${NODE_ENV:-development}"
if [ "$INHERITED_NODE_ENV" = "production" ]
then
echo ' Setting `NODE_ENV=development` to install dependencies for `npm build`'
export NODE_ENV=development
else
echo " Using \`NODE_ENV=${INHERITED_NODE_ENV}\`"
export NODE_ENV="${INHERITED_NODE_ENV}"
fi

echo "=====> Downloading Buildpack: $url"

if [[ "$url" =~ \.tgz$ ]] || [[ "$url" =~ \.tgz\? ]]; then
Expand Down

0 comments on commit 411505b

Please sign in to comment.