From 73beb391c44ed09e0399cf54a393651e23fbe93a Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 3 Nov 2023 20:31:09 +0200 Subject: [PATCH 1/3] babel.config - disable console logging on native prod builds But do keep error and warn logs --- babel.config.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/babel.config.js b/babel.config.js index 7de6926c850d..29825d80fd2e 100644 --- a/babel.config.js +++ b/babel.config.js @@ -78,6 +78,11 @@ const metro = { }, ], ], + env: { + production: { + plugins: ['transform-remove-console', {exclude: ['error', 'warn']}], + }, + }, }; /* From 7f6ef194c60f6b0451598aa5aec33a51c363b652 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 3 Nov 2023 20:32:08 +0200 Subject: [PATCH 2/3] babel.config - don't try to disable console logging on production webpack builds --- babel.config.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/babel.config.js b/babel.config.js index 29825d80fd2e..ab8efa583f35 100644 --- a/babel.config.js +++ b/babel.config.js @@ -17,16 +17,8 @@ const defaultPlugins = [ ]; const webpack = { - env: { - production: { - presets: defaultPresets, - plugins: [...defaultPlugins, 'transform-remove-console'], - }, - development: { - presets: defaultPresets, - plugins: defaultPlugins, - }, - }, + presets: defaultPresets, + plugins: defaultPlugins, }; const metro = { From 9579930dccbfe4f144d99dcaf87457f2da062114 Mon Sep 17 00:00:00 2001 From: Peter Velkov Date: Fri, 3 Nov 2023 20:33:27 +0200 Subject: [PATCH 3/3] babel.config - print some env and build info for more insights --- babel.config.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/babel.config.js b/babel.config.js index ab8efa583f35..64a433936eb7 100644 --- a/babel.config.js +++ b/babel.config.js @@ -99,11 +99,19 @@ if (process.env.CAPTURE_METRICS === 'true') { ]); } -module.exports = ({caller}) => { +module.exports = (api) => { + console.debug('babel.config.js'); + console.debug(' - api.version:', api.version); + console.debug(' - api.env:', api.env()); + console.debug(' - process.env.NODE_ENV:', process.env.NODE_ENV); + console.debug(' - process.env.BABEL_ENV:', process.env.BABEL_ENV); + // For `react-native` (iOS/Android) caller will be "metro" // For `webpack` (Web) caller will be "@babel-loader" // For jest, it will be babel-jest // For `storybook` there won't be any config at all so we must give default argument of an empty object - const runningIn = caller((args = {}) => args.name); + const runningIn = api.caller((args = {}) => args.name); + console.debug(' - running in: ', runningIn); + return ['metro', 'babel-jest'].includes(runningIn) ? metro : webpack; };