티스토리 뷰

728x90

 

"scripts": {
    "start": "react-scripts start",
    "start:stg": "env-cmd -f .env react-scripts start",
    "start:prd": "serve -s build",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "lint": "eslint 'src/**/*.{js,ts,tsx}'"
},

https://stackoverflow.com/questions/42458434/how-to-set-build-env-variables-when-running-create-react-app-build-script

 

How to set build .env variables when running create-react-app build script?

I'm using the following environment variable in my create-react-app: console.log(process.env.REACT_APP_API_URL) // http://localhost:5555 It works when I run npm start by reading a .env file:

stackoverflow.com

npm install --save-dev env-cmd
./node_modules/.bin/env-cmd -f ./stage.env npm build
728x90
댓글