PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How to tell React which .env file to use?

 August 21, 2022     environment-variables, react-native, reactjs     No comments   

Issue

I have a React app that I run with the command:

npm run dev

This launches the app and uses the .env.local file. I want to be able to configure a file called .env.production that will be used instead of .env.local when I run the command npm run prod.

These are my current scripts:

  "scripts": {
    "dev": "react-scripts start",
    "start": "serve -s build",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

How can I do this?


Solution

install npmjs.com/package/env-cmd

 "scripts": {
        "start": "react-scripts start",
        "start:local": "env-cmd -f ./.env.local react-scripts start",
        "start:Dev": "env-cmd -f ./.env.development react-scripts start",
        "start:QA": "env-cmd -f ./.env.test react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      }


Answered By - Ram Rana
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing