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

后端 未结 3 1585
难免孤独
难免孤独 2021-02-14 03:46

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

3条回答
  •  走了就别回头了
    2021-02-14 04:33

    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 :)

提交回复
热议问题