Hi,
I implemented this package because I want to deploy my react create app in multiple environments and I will have unique vars for each. eg:
env.local:
REACT_APP_API_URL=localhost:3000
env.staging:
REACT_APP_API_URL=api.staging.com
env.prod:
REACT_APP_API_URL=prod.staging.com
When i run APP_ENV=prod react-env --env APP_ENV -- react-scripts start it show the correct API_URL when logging env("API_URL") inside my running app when switching prod to staging etc. (logging window.__ENV gives undefined though, not sure why this is..)
So far so good.
Now in my deployments I want to use of react-scripts build instead of start. But how do I actually use it?
I don't find anything in the docs and I tried all kind of combos to try to get it working but I can't find the solution.
In the end I want everything in a Dockerfile, I was thinking something like this but it does not seem to work like this (I pass DEPLOY_ENV as a variable to the container) :
this is just one of the combos I tried:
RUN npm run build
ENTRYPOINT npx react-env --env DEPLOY_ENV --dest "build"
CMD serve -s -l 80 "./build"
the build folder is being served, ./build/__ENV.js is present but no env variables are available with env("API_URL")
I think it's a bit weird the docs only handle the dev start scripts but not the actual builds which is where the real need for dynamic environment variables comes into play, no?
I also tried several syntaxes out of docker but none seem to serve the env variables inside of my app
Hi,
I implemented this package because I want to deploy my react create app in multiple environments and I will have unique vars for each. eg:
env.local:REACT_APP_API_URL=localhost:3000
env.staging:REACT_APP_API_URL=api.staging.com
env.prod:REACT_APP_API_URL=prod.staging.com
When i run
APP_ENV=prod react-env --env APP_ENV -- react-scripts startit show the correct API_URL when logging env("API_URL") inside my running app when switchingprodtostagingetc. (logging window.__ENV gives undefined though, not sure why this is..)So far so good.
Now in my deployments I want to use of
react-scripts buildinstead of start. But how do I actually use it?I don't find anything in the docs and I tried all kind of combos to try to get it working but I can't find the solution.
In the end I want everything in a Dockerfile, I was thinking something like this but it does not seem to work like this (I pass DEPLOY_ENV as a variable to the container) :
this is just one of the combos I tried:
the build folder is being served,
./build/__ENV.jsis present but no env variables are available withenv("API_URL")I think it's a bit weird the docs only handle the dev start scripts but not the actual builds which is where the real need for dynamic environment variables comes into play, no?
I also tried several syntaxes out of docker but none seem to serve the env variables inside of my app