4

I want to define an url inside a .env file and then use it inside package.json using the cross-env package:

# .env
REACT_APP_TESET_URL=https://test.com
// package.json
{
  //...
  "scripts": {
    "start": "rescripts start"
    "start:test": "cross-env REACT_APP_MANUAL_URL=$REACT_APP_TEST_URL yarn start",
  }
}

but $REACT_APP_TEST_URL gets interpreted as a string.

I could of course pass in a REACT_APP_ENV_NAME variable via cross-env and then decide which .env variable to use with a switch statement inside my React app, but I would prefer to do it the way I described above.

is there a way to achieve this?

Michal Kurz
  • 1,592
  • 13
  • 41
  • maybe you could create another .env file with say `.env.manual` your necessary data and then reference that in your command like `env-cmd -f .env.manual yarn start`? here is [env-cmd](https://www.npmjs.com/package/env-cmd) – tanmay Jul 03 '20 at 08:54

0 Answers0