Production vs Environmental .env Files
There comes a time when you have worked hard to take your application from development to production. You've cleared your bugs and now you are ready to publish your React or Laravel application to the web, but you have this .env file and the configurations are set for your local environment, you could do different things, but what is the easiest way?
One of the easiest way to build your production application is to use one simple command. How do you do that? Simple, follow these steps.
$ touch .env.dev
$ touch .env.prod
$ npm install --save-dev env-cmd
"scripts": {
"dev": "vite",
"build:dev": "env-cmd -f .env.dev vite build",
"build:prod": "env-cmd -f .env.prod vite build"
},
$ npm run build:dev
$ npm run build:prod
[Old way]
"scripts": {
.....
"build": "NODE_ENV=development react-scripts build",
"build:prod": "NODE_ENV=production react-scripts build",
.....
},
$ npm run build
npm run build:prod
UPDATE: For some peole this is not working, try installing 'env-cmd' package - https://www.npmjs.com/package/env-cmd
More info: https://stackoverflow.com/a/75091721