How can remove console.log in the production build of a React application created using create-react-app?

Ajay picture Ajay · May 23, 2019 · Viewed 11.1k times · Source

How can remove console.log in the production build of a React application created using create-react-app CRA?

Answer

hello world picture hello world · Sep 16, 2019

this is what i did. create a helper folder with a file called ConsoleHelper.js

const ConsoleHelper = (data) => {
  if (process.env.NODE_ENV === 'production') return;
  console.log(data);
}

export default ConsoleHelper;

instead of console.log(data) do ConsoleHelper(data);

hope this helps. i console log alot :)