~/swaraj.dev
Back to all posts
March 20, 20261 min read

Trim Your React Native Bundle: Console Removal & Inline Requires

Learn how a couple of Babel tweaks—removing console statements and enabling inline requires—can shave megabytes off your RN bundle and speed up startup.

performancebundlereact-nativebabeloptimisation

Insight

In production builds, stray console.log calls and eager module loading are silent performance killers. Each console.* line adds dead code that the JS engine still parses, while loading whole modules up front inflates the initial bundle. By stripping console statements with babel-plugin-transform-remove-console and turning on Metro's inlineRequires, you let the JavaScript engine lazily load only what’s needed, cutting bundle size and improving cold‑start times.

Example

// babel.config.js
module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  env: {
    production: {
      plugins: ['transform-remove-console'], // removes all console.* calls
    },
  },
};

// metro.config.js (optional, for inline requires)
module.exports = {
  transformer: {
    inlineRequires: true,
  },
};

Takeaway

Enable transform-remove-console in production and set inlineRequires: true. Re‑bundle and you’ll see a leaner APK/IPA and noticeably faster app launch.