Skip to content

Commit

Permalink
Split bundle compatibility for runtime vars (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars authored Oct 8, 2018
1 parent 21a705a commit fe948bc
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions .profile.d/inject_react_app_env.sh
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

0 comments on commit fe948bc

Please sign in to comment.