dnmh
dnmh

Reputation: 2135

Webpack pass a variable into the start/build script

I have a React app which is built inside a Docker container when deployed. It all works as it should, no issues. I have an .env file for development with an API_URL variable and an .env.prod file for deployment with a different API_URL. The .env files get passed directly inside the start/build scripts, like this (for yarn start):

"start": "cross-env NODE_ENV=development env-cmd .env node server"

So, the API_URL variable is inside the .env file used in this script. My question is - can I somehow pass the variable to yarn start or yarn build? When I tried, for testing, adding the variable directly in the script, it didn't get picked up, like so: "start": "cross-env NODE_ENV=development API_URL="my api url" env-cmd .env node server".

Upvotes: 0

Views: 138

Answers (1)

felixmosh
felixmosh

Reputation: 35503

The usage is correct except that env_cmd is overriding that key.

You should use the --no-override flag so it won't.

The final line should like: API_URL="my api url" env_cmd .env --no-override node server"

Upvotes: 1

Related Questions