React Native 0.60.3 babel-plugin-transform-remove-console 不工作

The*_*i M 9 reactjs babeljs react-native

我正在尝试从我的 react-native 应用程序的输出中删除 console.log 输出,但是当我运行时

ENVFILE=.env.production react-native run-android --variant=release

亚行日志猫

我仍然看到我的应用程序的数据被记录到控制台。

我使用了以下文档:https : //facebook.github.io/react-native/docs/performance.html#using-consolelog-statements

这是我的 .babelrc 文件:

{
  "presets": ["react-native"],
  "env": {
    "production": {
      "plugins": ["transform-remove-console"]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么?我在 react-native 0.60.3 上使用 "babel-plugin-transform-remove-console": "^6.9.4",

muk*_*mar 21

我有"@babel/core": "^7.5.5"并且React Native 文档中"react-native": "^0.60.5"
描述的方法对我不起作用。经过多次尝试和错误并在 GitHub 上探索问题后,我得到了它的工作:


babel.config.js添加这个 -

module.exports = api => {
  const babelEnv = api.env();
  const plugins = [];
  //change to 'production' to check if this is working in 'development' mode
  if (babelEnv !== 'development') {
    plugins.push(['transform-remove-console', {exclude: ['error', 'warn']}]);
  }
  return {
    presets: ['module:metro-react-native-babel-preset'],
    plugins,
  };
};
Run Code Online (Sandbox Code Playgroud)

要查看更改运行使用 npm start -- --reset-cache


更多信息在