score:1
you'll need to take a look at defineplugin.
its job is to find instances of a given string, then replace them with some other string. add this code to your plugins array to configure it to build the production version of react.
new webpack.defineplugin({
'process.env.node_env': json.stringify('production')
})
then make sure you are using the uglifyjs plugin too and that it comes after the defineplugin
in your config.
this will replace all of the following expressions:
if (process.env.node_env === "development") {
// do slow development code
}
with code that looks like:
if ("production" === "development") {
// do slow development code
}
uglify can recognise this at compile time as an if
expression that will never be true, and remove the entire statement.
if you want to remove all console.log
statements, the easiest way is to make it a no op in an initialization file.
if (process.env.node_env === "production") {
console.log = () => {};
console.info = () => {};
// ...
}
make sure this code runs before before any of the files that might have logging statements in.
Source: stackoverflow.com
Related Query
- Optimizing react webpack config to production
- Add production into development React Webpack config
- Why is React Webpack production build showing Blank page?
- How to update webpack config for a react project created using create-react-app?
- Why does production build of React app (with Webpack and Babel) use wrong development env with HMR, which causes errors?
- Webpack config for Code splitting not working for production build
- React + Webpack + Material UI styling breaking in production
- How do I get webpack to transform the react production files?
- React Router - Route not working on Refresh in webpack production build
- Config antd with react and webpack
- Searching for Webpack config for React Components Library with Typescript, SASS & CSS Modules via SASS support
- Removing console.log in production React JS with WebPack / Babel
- React webpack bundle for production
- Error using css modules in typescript react with webpack config
- Putting React app into production with Webpack
- React webpack config: is it possible to replace config for only one plugin in array, without reset an array of plugins?
- Queries presets vs loaders in webpack config in react app
- Issues adding additional entry point to webpack config (create react app)
- webpack config for bootstrap fonts in react
- Webpack production build always returns This page is using the development build of React
- Print styles not applied in production with webpack / react
- Output multiple React apps from one Webpack config
- using webpack ProvidePlugin in React storybook custom webpack config
- correct webpack config for babel 6, react hot load, webpack middleware
- React - Django webpack config with dynamic 'output'
- Hash router works in production but browser router doesn't in react webpack app
- Webpack doesn't create react build production version
- How do you configure Webpack to clear the React Warning for production minification?
- React and redux webpack config error
- React & Webpack & Docker: Inject env's at runtime in production to the docker-container
More Query from same tag
- redux-form: Change specific field value on click
- Create HTML file from React components
- React - Access JSON array data and its sub data
- Destructure Event parameters and only pass type check if id is of a certain value
- How to define props on framer-motion styled-component? (PSA)
- Wordpress Gutenberg React – render variable with HTML
- Material UI: Grid does not put select in row
- Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method
- Check if item exists in array React
- How do I appropriately handle field change events in React using a custom hook?
- Input value in child component not being updated by setState
- React, onChange and onClick events fires simultaneously
- 'recipe' is not defined when mapping a array
- Property does not exist on type - TypeScript
- Filtering array to remove filtered object in react
- Application Insights React plugin
- How do I loop through the elements of an object and return its value in TypeScript&React?
- dispatch action and redirect by calling function without page reload in react redux ( Page Reload Problem )
- displaying <li> elements left and right side according to the condition
- MapDispatchToProps include all actions
- react-datetime-YouCanBookMe error time and update state
- TypeError: this.activateMode is not a function (Gutenberg WordPress)
- I want to display a div when user hover over a sign in element but div should be displayed when user moves the mouse to that div other in ReactJS
- Safari clipboard error "TypeError: undefined is not an object"
- React TypeScript: How to get form values, and response codes using fetch
- How to force Apollo Client to use cached data for detail view page
- Create React Component Library using CRACO with Create React App
- How to purge all except what I don't want to purge in redux-persist?
- window.matchMedia is not a function
- React: find string in array and rename it