I want to add a .env file in my React application. The project wasn't created using Create React APP. And without Webpack. I'm struggling to find a proper solution for this
1 Answer
For a easy solution you could try to use react-app-env.
You could folllow this simple guide. In brief:
install it:
yarn add --dev react-app-env (or npm install --save-dev react-app-env)change the start and build scripts:
"scripts": { "start": "react-app-env start'", "build": "react-app-env build'", "test": "react-app-env test'", ... }finally add at least two configuration files (on project root folder):
development.envandproduction.env. By defaultdevelopment.envis used imported onnpm startandnpm test, andproduction.envonnpm build.