2

It is abundantly clear on how to pass ENV variables into the code when you create/build your webpack. See this existing thread: Passing environment-dependent variables in webpack

However, I'd like to know if there is a way to have the already webpacked/bundled .js code update the variables used based on what is read in the ENV vars without having to do another webpack/build using different ENV vars.

Scenario:

  1. Development build webpack.config build where: new webpack.DefinePlugin({ 'APISECRET': JSON.stringify(process.env.APISECRET || 'mydevapisecretkey') }), This creates webpacked files that picks up my development environment key and is hosted on a development environment web server.
  2. Take these same exact files and move them to a production environment where APISECRET ENV on the hosted webserver has the production value present.

Problem: Now the bundled code still references the value present from the development environment even though there is a new value for the APISECRET ENV variable present on the host.

If this is not possible, it would be great to know if there are any alternative solutions. This is per 12 factor best practices: https://12factor.net/config

David Tesar
  • 2,136
  • 1
  • 11
  • 9
  • 1
    Is this helpful? https://stackoverflow.com/questions/40954400/how-to-configure-a-spa-on-loading I had trouble providing my answer because of SO rules but I think it is there. Someone neg'ed it as well for some strange reason. Go figure :-) – Ashley Aitken Jun 10 '17 at 01:22
  • Man, I've been looking all over the place on how to solve this as well. If you figure it out let me know! – byumark Jun 10 '17 at 02:44
  • It looks like the clientconfig could do it but as mentioned I worry a little bit about the security aspect since it is stored as a cookie. It says it immediately deletes it, but is the secret show on the client web browser at all? https://stackoverflow.com/a/40957304/7994299 – David Tesar Jun 12 '17 at 05:08

0 Answers0