|
|
|
|
|
by sngz
2242 days ago
|
|
So the issue I'm referring to is this, which has been open since 2017 https://github.com/facebook/create-react-app/issues/2353 There's a slew of workarounds offered in that github issue, most people (including another team in my org) opted to just rebuild the app every time a docker container is created which kind of defeats one of the major pros of using docker IMO. I ultimately ended up forking off this repository and customizing it to my needs https://github.com/beam-australia/react-env that solution in itself is very hacky. as far as I know, vue doesn't have this feature either but I think next.js and nuxt.js does. |
|
I probably don't appreciate the complexity of the issue, but I would say environment variables are not React's concern; it’s up to you how to architect your code. If you want runtime environment variables, then either add them to the html that React will render into, so that the javascript code can read these variables in before rendering, or have an api endpoint that your app will query before or during rendering and will get all the relevant config information from it.
> but I think next.js and nuxt.js does
Probably because they server-side-render. And even if your app renders on the client side; even if you don't use next, nuxt or whatever, there is no-one stopping you from dynamically serving the html skeleton with the relevant variables in it.
But then, it all probably has been mentioned in that issue. I wonder why it wouldn't be a good solution.