Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using react-env on builded project #131

Open
pieterjandebruyne opened this issue Oct 16, 2023 · 0 comments
Open

Using react-env on builded project #131

pieterjandebruyne opened this issue Oct 16, 2023 · 0 comments

Comments

@pieterjandebruyne
Copy link

pieterjandebruyne commented Oct 16, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant