Skip to content

Environment variables in react build

React JS

Using environment variables we can change the default behavior of react scripts.

To set environment variables in React build, first install the:

"env-cmd" package

npm i --save env-cmd

Create an environment file, e.g env.production or env.iis

Add variables like

PUBLIC_URL=/myurl/
(for base url)
BUILD_PATH=..//..//publish (where to store the build output)
BROWSER=none (don't open browser)

Then add the variable loading in the npm script:

e.g.

"build": "env-cmd -f .env.iis react-scripts build"

Post a Comment

Previous Post Next Post