Skip to content

Add tree-shaking for unused Expo modules to reduce bundle size #217

@RUKAYAT-CODER

Description

@RUKAYAT-CODER

Background

The project imports entire Expo modules but uses only a small subset of exports. Enable tree-shaking in metro config and webpack to eliminate unused code. This requires proper ES6 module exports and sideEffect: false configuration.

Description

Many Expo modules are imported in full even when only specific exports are used. By configuring Metro bundler and package.json correctly, we can enable tree-shaking to remove unused exports, reducing output size by 8-12%.

Current Behavior

Unused Expo module code bundled in production (~200KB of unused code)

Expected Behavior

Only used Expo exports included in bundle. Unused code automatically stripped by bundler.

Impact

📦 Direct bundle size reduction of 8-12%
⚡ Faster app startup
💡 Improved performance on low-bandwidth networks

Acceptance Criteria

  • Configure metro.config.js to enable tree-shaking
  • Add sideEffects: false to package.json
  • Audit all Expo imports for unused exports
  • Convert unused full imports to named imports
  • Verify bundle size reduction with expo analyze
  • Test app functionality - no missing dependencies
  • Document tree-shaking configuration in dev guide

Implementation Hints

Update metro.config.js with inlineRequires: true. Set optimization: true in production. Use expo build:web --analyze to identify removable code.

Performance Metrics

Before:

  • bundleSize: 2.8 MB

After (Target):

  • bundleSize: 2.45 MB (-12%)

Related Issues

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions