How can remove console.log in the production build of a React application created using create-react-app?
build, console.log, create-react-app, reactjs
Solution
I am using this approach to avoid ejecting `react-scripts`
if (process.env.NODE_ENV === 'production') {
console.log = () => {}
console.error = () => {}
console.debug = () => {}
}
`index.js`
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import './styles/main.scss'
// replace console.* for disable log on production
if (process.env.NODE_ENV === 'production') {
console.log = () => {}
console.error = () => {}
console.debug = () => {}
}
ReactDOM.render(<App />, document.getElementById('root'))
Problem
How can remove console.log in the production build of a React application created using create-react-app CRA?