score:17
as per the docs, we cannot override node_env, but there is a room to create our own custom variables starting with react_app_. so i configured to look as below:
reference: https://facebook.github.io/create-react-app/docs/adding-custom-environment-variables
"staging": "concurrently -k \"npm:staging-server\" \"cross-env react_app_environment='staging' port=3003 react-scripts start\"",
and inside my ui application, i can fetch its value by consoling it like this:
console.log('react_app_environment => ', process.env.react_app_environment);
score:1
use cross-env in front of node_env.
npm i -g cross-env
"staging": "concurrently -k \"npm:staging-server\" \"cross-env node_env='staging' port=3003 react-scripts start\"",
score:2
easiest approach is to add it directly in your command:
"scripts": {
"start": "./node_modules/.bin/nodemon server.js",
"start:prod": "node_env=prod node server.js",
},
score:5
i build the build with react_app_stage and use it in my application as process.env.react_app_stage.
"scripts": {
"analyze": "source-map-explorer 'build/static/js/*.js'",
"build-css": "node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/",
"watch-css": "npm run build-css && node-sass-chokidar --include-path ./src --include-path ./node_modules src/ -o src/ --watch --recursive",
"start-js": "react-scripts start",
"start": "react_app_stage=local npm-run-all -p watch-css start-js",
"build": "npm run build-css && react-scripts build",
"build-dev": "react_app_stage=dev react-scripts build",
"build-prod": "react_app_stage=prod react-scripts build",
"build-qa": "react_app_stage=qa react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
Source: stackoverflow.com
Related Query
- How to set NODE_ENV from package.json for react
- How to set node env variables (runtime) after build the React project?
- How to set a general onchange for the dynamic form fields coming from api in react js.?
- how to set the default value for the input from a db in React
- How can i set onchange in a map with React for Switch Buttons from React-Bootstrap?
- How to set the data from my API as initial state for my react component?
- How would I set up audio streaming from a Node server to React frontend?
- How to set state of a react component with a specific item from a returned json object?
- How to set state at the server for data from API using react redux
- fetch wrapped in request.js in react boilerplate: how to handle error from json body for Spring backend
- how to loop throgh array of object from axios json respone in react js and set them in div?
- How to set a JSON object from local.storage using setState with React Hooks
- How to publish a typescript package for both node and react
- How to set elements from a json file into a React component
- How to set dynamic attributes in React Input Component from json props
- How to get JSON from REACT JS to implement in NODE js
- How to set state of response from axios in react
- React tutorial - how do I start the node server for a reactJs application?
- ReactJS - How can I set a value for textfield from material-ui?
- How to set React component state and props from browser
- How can I set initial React state from API data?
- How to set headers for a React app created using 'create-react-app'
- How to set React default props for object type
- How to set placeholder for dropdown in react js?
- React Navigation: How to update navigation title for parent, when value comes from redux and gets updated in child?
- CDN links for React packages and how to import it when using react using the scripts from CDN
- How to set up analytics on React Native for iOS
- How do you set the Typescript type for useRef hook in React Native?
- How to acess React context from Apollo set Context Http Link
- How to make React input onChange set state only after onChange stops firing for set time?
More Query from same tag
- React Hooks - Dynamically Render Text Inputs and Store Inputs as One Array
- React Error: NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node
- React/Typescript - expects at least '3' arguments, but the JSX factory 'React.createElement' provides at most '2'. TS622
- Why is this React function returning NaN?
- How to add an actual user id into react hooks
- React-router-dom link route to target page after refresh
- How to make a table cell clickable(and add a separate function) of the row which is already clickable for different functionality?
- What does the meaning of this line of codes ` skills: { ...this.state.skills, [name]: checked }`?
- How can I add heading in a box component in Material UI?
- Are functional components turned into class components under the hood?
- Callback function for ClickAwayListener stop midway on execution
- Testing React with Mocha and Chai
- Set a variable to true if all the props are defined
- How do I loop through child array and check if component exists React Testing Library
- Formik Chakra-ui select not using value
- Partial css in react appearing in the whole app
- Validate the Sign-up Password of user in React-js
- gh-pages -d build fails on 'npm run deploy'
- ES6 import statements that assume .jsx ending in webpack
- React - how to extend a component that has child components and keep them?
- Render react component onClick
- Problems reordering child components from parent's state
- How to add dynamically property for the parameter of React setState method
- Pass Dynamic variable as prop from slug
- Transition between routes in react-router-dom v6.3
- Error of Connection already released while connecting backend with frontend
- How to check if data has a defined type in ternary operator Typescript
- How to target single item in list with onClick when mapping in ReactJS?
- On cancel click not able to set previous data in my react app
- Change locale for Chart.js in React