Skip to content

Commit 792c9ff

Browse files
authored
Merge pull request #1 from mars/react-app-env-vars
Support custom `REACT_APP_*` env vars during build
2 parents b5b5a02 + 691ff1c commit 792c9ff

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bin/compile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ CACHE_DIR=$2
1515
ENV_DIR=$3
1616
BP_DIR=`cd $(dirname $0); cd ..; pwd`
1717

18+
export_env_dir() {
19+
local env_dir=$1
20+
local whitelist_regex=${2:-''}
21+
local blacklist_regex=${3:-'^(PATH|GIT_DIR|CPATH|CPPATH|LD_PRELOAD|LIBRARY_PATH|IFS)$'}
22+
if [ -d "$env_dir" ]; then
23+
for e in $(ls $env_dir); do
24+
echo "$e" | grep -E "$whitelist_regex" | grep -qvE "$blacklist_regex" &&
25+
export "$e=$(cat $env_dir/$e)"
26+
:
27+
done
28+
fi
29+
}
30+
1831
cd $BUILD_DIR
1932

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

42+
# Support custom `REACT_APP_*` env vars during build.
43+
# https://github.com/facebookincubator/create-react-app/blob/v0.2.3/template/README.md#adding-custom-environment-variables
44+
export_env_dir "$ENV_DIR" '^REACT_APP_'
45+
2946
# Build the javascript bundle
3047
npm run build

0 commit comments

Comments
 (0)