-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split bundle compatibility for runtime vars (#14)
- Loading branch information
Showing
1 changed file
with
15 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,28 @@ | ||
#!/bin/bash | ||
|
||
# Fail immediately on non-zero exit code. | ||
set -e | ||
# Debug, echo every command | ||
#set -x | ||
|
||
# Each bundle is generated with a unique hash name to bust browser cache. | ||
# Use shell `*` globbing to fuzzy match. | ||
js_bundle="${JS_RUNTIME_TARGET_BUNDLE:-/app/build/static/js/main.*.js}" | ||
# create-react-app v2 with Webpack v4 splits the bundle, so process all *.js files. | ||
js_bundles="${JS_RUNTIME_TARGET_BUNDLE:-/app/build/static/js/*.js}" | ||
# Get exact filenames. | ||
js_bundle_filenames=`ls $js_bundles` | ||
|
||
if [ -f $js_bundle ] | ||
if [ ! "$?" = 0 ] | ||
then | ||
echo "Error injecting runtime env: bundle not found '$js_bundles'. See: https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-custom-bundle-location" | ||
fi | ||
|
||
# Get exact filename. | ||
js_bundle_filename=`ls $js_bundle` | ||
|
||
# Fail immediately on non-zero exit code. | ||
set -e | ||
|
||
for js_bundle_filename in $js_bundle_filenames | ||
do | ||
echo "Injecting runtime env into $js_bundle_filename (from .profile.d/inject_react_app_env.sh)" | ||
|
||
# Render runtime env vars into bundle. | ||
ruby -E utf-8:utf-8 \ | ||
-r /app/.heroku/create-react-app/injectable_env.rb \ | ||
-e "InjectableEnv.replace('$js_bundle_filename')" | ||
else | ||
echo "Error injecting runtime env: bundle not found '$js_bundle'. See: https://github.com/mars/create-react-app-buildpack/blob/master/README.md#user-content-custom-bundle-location" | ||
fi | ||
-r /app/.heroku/create-react-app/injectable_env.rb \ | ||
-e "InjectableEnv.replace('$js_bundle_filename')" | ||
done |