Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react load different .env for local, dev, and prod

// create 4 env files to represent local, dev, qa, prod & name them with
// the convention of .env.<environment> e.g. local env would be .env.local
// tldr you should have 4 files in the repo root named:
// .env.production, .env.development, .env.qa, and .env.local 

// react env vars should be prefixed with `REACT_APP` - this allows you
// to create envs based around react without interfering with node. 

// Add the code below to your package.json scripts object.
// we're telling shell to run a file, which uses . to run the contents
// of the given env file making them available to node. The same as
// setting each env var on the cmd prior to running node. Test locally
// by adding REACT_APP_NAME=TEST to your .env.local & using the node repl 
// by running: sh -ac '. ./.env.local; node' & inside the node repl you
// can access the env var process.env.REACT_APP_NAME which equals "TEST".
"scripts": {
    "build:local": "REACT_APP_ENV=local npm run build",
    "build:dev": "REACT_APP_ENV=development npm run build",
    "build:qa": "REACT_APP_ENV=qa npm run build",
    "build:prod": "REACT_APP_ENV=production npm run build",
    "build": "sh -ac '. ./.env.${REACT_APP_ENV}; node scripts/build.js'",
    "start:local": "REACT_APP_ENV=local npm run start",
    "start:dev": "REACT_APP_ENV=development npm run start",
    "start:qa": "REACT_APP_ENV=qa npm run start",
    "start": "sh -ac '. ./.env.${REACT_APP_ENV}; NODE_ENV=development node scripts/start.js'"
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: change styles when element enters viewport 
Javascript :: diffrence b/w render and reload 
Javascript :: At line:1 char:1 + nodemon server.js 
Javascript :: get previous url javascript 
Javascript :: javascript ascii to hex 
Javascript :: transpose an array in javascript 
Javascript :: how to get the current date and time in javascript 
Javascript :: mandelbrot set javascript 
Javascript :: js detect scroll 
Javascript :: Send Data Using Fetch With Then Syntax 
Javascript :: check if 2 arrays are equal javascript 
Javascript :: javascript work out age from date of birth 
Javascript :: Could not resolve dependency: npm ERR! peer reac 
Javascript :: why my bootstrap classes is not working on onclick event in react 
Javascript :: js extract options from select 
Javascript :: js object every 
Javascript :: how to take input from user nodejs 
Javascript :: javascript convert to two decimal places 
Javascript :: flutter jsonDecode UTF8 
Javascript :: generate module with routing in angular 
Javascript :: format number to 2 digits javascript 
Javascript :: remove prefix js 
Javascript :: jquery on input 
Javascript :: angular formarray remove all 
Javascript :: sending form data with fetch using js 
Javascript :: js console log input value 
Javascript :: convert json string to javascript object 
Javascript :: jquery trim 
Javascript :: gatsby-plugin-create-client-paths 
Javascript :: get json from url c# 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =