Michal Kurz
Michal Kurz

Reputation: 2095

Referencing a .env variable inside package.json with cross-env package

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?

Upvotes: 5

Views: 2531

Answers (0)

Related Questions