score:0
Accepted answer
you can create one file config with keys for example "default" and "production". once import with file, check process.env and return actual config object.
const config = require('./data/config.json');
function getconfig() {
let customconfig = config['default'];
if (process.env.node_env === 'production') {
customconfig = config['production'];
}
return customconfig;
}
score:1
another idea - add to your wabpack alias
resolve: {
alias: {
'config/data': path.resolve(__dirname, `./data/${process.env.node_env}`)
}
}
and call it from component this way:
import { data } from 'config/data';
Source: stackoverflow.com
Related Query
- Import different file depending on environment
- React: How to import images dynamically depending on environment variables?
- How to move react event handlers to separate file ,export and then import for reuse in multiple different functional components?
- How to setup DevOps build for creat-react-app project with different environment vars depending on built branch?
- Import html string on a different file on react. Using prismjs to display code highlighting
- Import async function from different file to component
- How to import just one function from different file into other?
- How to import a CSS file in a React Component
- Import JSON file in React
- Import JavaScript file and call functions using webpack, ES6, ReactJS
- ReferenceError: You are trying to `import` a file after the Jest environment has been torn down
- How to import a .txt file from my source?
- Next.js - import css file does not work
- using css modules, how can I import classes from a file
- How import object from external JS file in React JS using web pack
- import scss file with Storybook
- How to import a scss file into a typescript file
- React + TypeScript: 'React' refers to a UMD global but the current file is a module. Consider adding an import instead. (Justification)
- Import CSS File to Styled Component
- React: import csv file and parse
- Conditional Import based on environment variable
- How to import scss file as variable in react with typescript
- How to import js modules (with absolute path) in my typescript file in React application?
- how to import HTML file into React component and use it as a component?
- Use different loader in Webpack depending on from where I'm importing
- Webpack check file exist and import in condition
- Import and read the contents of a CSS file as text (React/webpack)
- Rendering an environment variable to the browser in a react.js redux production build running in different environments
- how to import data in react from a js file to use in components
- Dynamically import language json file for react / react-intl
More Query from same tag
- Use click handler to change color of button when there are multiple buttons using the same function
- How to `navigate` to new screen from button in header with react-navigation?
- Remove item from array with click function
- Access yLabel for specific bar in chartJs without click
- setState also changes screen props
- Pass data from actions in reducer
- Filtering state logic for table react for multiple select dropdowns
- Prevent Gatsby page at a specific domain path from appearing in Google Search
- Changing the value of an element onclick in ReactJS
- How do I send data from React to Node server and back result to React?
- React + Jest: Test that setTimeOut didn't get called
- Dynamic pages in Next.js won't link back to normal pages
- Passing a child component to an API component
- React Routing with Express, Webpack dev middleware, React router dom
- React scrollTop=0 for componentDidMount not working:
- Dynamic page pagination is not working in react table
- Iterating a row with 2 columns
- Update swiper effect with swiperjs react
- Redux Dev Tools not working for large action payload
- Socket IO - server not connecting with my react client
- How do I implement protected client routes?
- React Splitting strings in an array
- How to fix 'element implicitly has an 'any' type. TS7031' for function?
- React JS updating setState in a for loop
- Why am I getting the error message "Property 'then' does not exist on type 'AsyncThunkAction'"?
- How to insert HTML in Draft.js?
- How do I send props from one component to another component, outside the render?
- Handle checkboxes with useState object
- Should global css be put in each component or the root component (webpack entry file)?
- How to share state (react)between electron's multiple windows?