metro-minify-swc

raw JSON →
1.0.0-alpha verified Fri May 01 auth: no javascript

A drop-in replacement minifier for Metro bundler that uses SWC (Speedy Web Compiler) for fast JavaScript minification. Version 1.0.0-alpha is experimental and may not be stable. SWC's Rust-based implementation aims to provide better performance than Metro's default minifier. Requires metro >=0.80.0. Provides TypeScript types.

error Error: Cannot find module 'metro-minify-swc'
cause Package not installed or not in node_modules.
fix
Run npm install --save-dev metro-minify-swc (or yarn/pnpm equivalent).
error Error: Minifier path not found: metro-minify-swc
cause Metro cannot resolve the minifier module.
fix
Ensure the package is installed and check that metro.config.js uses the correct string for minifierPath.
error TypeError: Cannot read properties of undefined (reading 'compress')
cause minifierConfig is undefined or not an object.
fix
Set minifierConfig to an empty object or a proper configuration object.
deprecated Package is 1.0.0-alpha and experimental; API may change without notice.
fix Pin exact version and monitor releases for breaking changes.
gotcha minifierConfig must be an object; passing undefined or null can cause errors.
fix Always provide an empty object if no configuration is needed: minifierConfig: {}.
gotcha Metro's default minifier options are not automatically applied; you must specify all desired options.
fix Explicitly set all minifier options in minifierConfig, including defaults.
gotcha SWC minifier may produce slightly different output than Metro's default (Terser-based) minifier; test thoroughly.
fix Verify bundle behavior in development and production environments.
npm install metro-minify-swc
yarn add metro-minify-swc
pnpm add metro-minify-swc

Shows how to configure Metro's transformer to use metro-minify-swc with custom compress and mangle options.

// metro.config.js
module.exports = {
  transformer: {
    minifierPath: 'metro-minify-swc',
    minifierConfig: {
      compress: {
        drop_console: true,
        unused: true,
      },
      mangle: {
        toplevel: true,
      },
    },
  },
};