-1

We are using Drone and terraform for CI/CD for react application. Can you please help me to create environment variable dynamically during build.

M M
  • 47
  • 3
  • What you have tried so far? It's a good practice to include more details, regarding the trial/fails and as well as details about the codebase or configs. – Aren Hovsepyan May 06 '21 at 16:07

2 Answers2

0

Setting env at build time means that bundle will only work in a particular environment. You will need seperate builds for each env.

Raskolnikov
  • 121
  • 2
  • 7
-1

Remember that your env variables have to start with REACT_APP_. Add an .env file containing REACT_APP_MYVARIABLE=something and build your app as usual or juzt build it like so: (windows) set "REACT_APP_MYVARIABLE=something" && npm run build, (macOS, linux) REACT_APP_MYVARIABLE=something npm run build. Then, ou can access your env variable from within your code like so: process.env.REACT_APP_MYVARIABLE.

k-wasilewski
  • 3,943
  • 4
  • 12
  • 29
  • Thank you for checking. I have created .env file which has variables assigned with plain text values. I am wondering is there any way we can dynamically provide the values while building an application. – M M May 06 '21 at 16:27
  • I precisely wrote that. – k-wasilewski May 06 '21 at 16:34