Skip to content

Commit

Permalink
Merge pull request #1 from mars/react-app-env-vars
Browse files Browse the repository at this point in the history
Support custom `REACT_APP_*` env vars during build
  • Loading branch information
mars authored Aug 25, 2016
2 parents b5b5a02 + 691ff1c commit 792c9ff
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bin/compile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ CACHE_DIR=$2
ENV_DIR=$3
BP_DIR=`cd $(dirname $0); cd ..; pwd`

export_env_dir() {
local env_dir=$1
local whitelist_regex=${2:-''}
local blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|IFS)$'}
if [ -d "$env_dir" ]; then
for e in $(ls $env_dir); do
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
export "$e=$(cat $env_dir/$e)"
:
done
fi
}

cd $BUILD_DIR

# Set the web root to the build/ directory
Expand All @@ -26,5 +39,9 @@ else
echo '{ "root": "build/" }' > static.json
fi

# Support custom `REACT_APP_*` env vars during build.
# https://github.com/facebookincubator/create-react-app/blob/v0.2.3/template/README.md#adding-custom-environment-variables
export_env_dir "$ENV_DIR" '^REACT_APP_'

# Build the javascript bundle
npm run build

0 comments on commit 792c9ff

Please sign in to comment.