Skip to content

⚡ 36x faster Metro transforms for React Native. Rust-powered (OXC). Drop-in Babel replacement.

License

Notifications You must be signed in to change notification settings

ecrindigital/facetpack

Facetpack

⚡ 36x faster Metro transforms for React Native
Rust-powered. Drop-in Babel replacement.

npm version npm downloads GitHub stars


Performance

Benchmark Babel Facetpack Speedup
Transform (small) 244 µs 7.8 µs 31x
Transform (large) 2.47 ms 64 µs 38x
Resolve (cold) 31.6 ms 10.8 ms 3x

Tested on Apple M3 Max

Quick Start

npm install @ecrindigital/facetpack
// metro.config.js
const { getDefaultConfig } = require('expo/metro-config')
const { withFacetpack } = require('@ecrindigital/facetpack')

module.exports = withFacetpack(getDefaultConfig(__dirname))

That's it.


Part of the Facet Ecosystem

Facetpack is the foundation of Facet, the modern toolchain for React Native.

Coming Soon Description
🌳 Tree-shaking 30% smaller bundles
🩺 Facet Doctor Diagnose & auto-fix issues
⚡ Facet CLI Faster dev server
🤖 f0 AI component generation
more tools coming soon

⭐ Star this repo to follow along!


How it works

┌─────────────────────────────────────────────────────────────┐
│                        Metro Build                          │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  User Code (.ts, .tsx)                                      │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐     │
│  │   Parse     │ -> │  Transform  │ -> │  Codegen    │     │
│  │   (OXC)     │    │   (OXC)     │    │   (OXC)     │     │
│  └─────────────┘    └─────────────┘    └─────────────┘     │
│                                                             │
│  Node Modules (Flow packages)                               │
│  ┌─────────────┐    ┌─────────────┐    ┌─────────────┐     │
│  │   Parse     │ -> │  Transform  │ -> │  Codegen    │     │
│  │  (Babel)    │    │  (Babel)    │    │  (Babel)    │     │
│  └─────────────┘    └─────────────┘    └─────────────┘     │
│                                                             │
│  Resolution                                                 │
│  ┌─────────────────────────────────────────────────────┐   │
│  │  Batch Resolve (OXC Resolver via NAPI)              │   │
│  │  Single FFI call for all imports in a file          │   │
│  └─────────────────────────────────────────────────────┘   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Architecture

packages/
├── facetpack/           # Metro integration (TypeScript)
│   ├── withFacetpack    # Config wrapper
│   ├── transformer      # OXC transformer + Babel fallback
│   └── resolver         # Cached batch resolver
│
└── facetpack-native/    # Native bindings (Rust + NAPI)
    ├── oxc_parser       # Parsing
    ├── oxc_transformer  # TS/JSX transformation
    ├── oxc_codegen      # Code generation
    └── oxc_resolver     # Module resolution

Options

module.exports = withFacetpack(config, {
  // JSX runtime: 'automatic' (default) or 'classic'
  jsxRuntime: 'automatic',

  // JSX import source for automatic runtime
  jsxImportSource: 'react',

  // JSX pragma for classic runtime
  jsxPragma: 'React.createElement',
  jsxPragmaFrag: 'React.Fragment',

  // File extensions to transform
  sourceExts: ['ts', 'tsx', 'js', 'jsx', 'mjs', 'cjs'],
})

Debug Mode

Enable debug logging:

FACETPACK_DEBUG=1 npx expo start

Limitations

  • Flow packages (react-native core, reanimated, gesture-handler, etc.) use Babel fallback
  • OXC doesn't support ES5 class transformation yet (not needed for Hermes)

Run Benchmarks

cd examples/benchmark
bun run.ts                    # Full benchmark with Metro build
bun run.ts --transformer-only # Skip Metro build benchmark

Development

# Install dependencies
bun install

# Build native bindings
cd packages/facetpack-native
bun run build

# Build TypeScript package
cd packages/facetpack
bun run build

# Run tests
bun test

License

MIT - Ecrin Digital

About

⚡ 36x faster Metro transforms for React Native. Rust-powered (OXC). Drop-in Babel replacement.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •