使用yarn和npm从React Native应用程序中删除console.log以提高性能

问题描述 投票:0回答:2

使用 console.log 语句是 JavaScript 应用程序(包括 React Native 应用程序)中最常见的调试模式之一。发布 React Native 应用程序时将控制台语句保留在源代码中可能会导致 JavaScript 线程出现一些大瓶颈。

android reactjs node.js react-native console
2个回答
0
投票
npm install babel-plugin-transform-remove-console --save-dev
yarn add babel-plugin-transform-remove-console -D

编辑 babel.config.js

 module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  env: {
    production: {
      plugins: ["transform-remove-console"],     //removing consoles.log from app during release (production) versions
    },
  },
};

或.babelrc

{
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}

0
投票

只需将这些行放入

index.js
文件中:

if (!__DEV__) {
  console.log = () => {}
}
© www.soinside.com 2019 - 2024. All rights reserved.