Skip to content

Remove browser/replay from mobile bundles to lower bundle size #3718

Closed
@krystofwoldrich

Description

@krystofwoldrich

Description

Metro currently doesn't support tree shaking out of the box. And so all @sentry/* dependencies are included in the final bundle.

Some packages can be easily excluded using the metro resolver options:

Current solution

const config = {
  resolver: {
    resolveRequest: (context, moduleName, platform) => {
      if (moduleName.includes('@sentry/replay')) {
        return { type: 'empty' };
      }
      return context.resolveRequest(context, moduleName, platform);
    },
  },
};

Proposed solution

Sentry Metro config will automatically remove web replay for mobile platforms and expose an option to remove it for web builds.

const { withSentryConfig } = require('@sentry/react-native/metro');

const m = mergeConfig(getDefaultConfig(__dirname), config);
module.exports = withSentryConfig(m, { includeWebReplay: true });

Metadata

Metadata

Type

No type

Projects

Status

Done

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions