Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/platforms/react-native/manual-setup/metro.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,37 @@ const config = getSentryExpoConfig(__dirname, {
});
```

### Reduce Bundle Size

If you're not using the Session Replay or User Feedback features, you can exclude their web-only packages from the bundle by opting out via the Metro Plugin options. When set to `false`, the Sentry Metro Plugin resolves the matching Sentry sub-packages to an empty module so they're not included in the output bundle.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we simplify this mentioning if users aren't targeting React Native for web, here is an idea:

Suggested change
If you're not using the Session Replay or User Feedback features, you can exclude their web-only packages from the bundle by opting out via the Metro Plugin options. When set to `false`, the Sentry Metro Plugin resolves the matching Sentry sub-packages to an empty module so they're not included in the output bundle.
If you're not using the React Native for Web, you can exclude their web-only packages like session replay and user feedback from the bundle by opting out via the Metro Plugin options. When set to false, the Sentry Metro Plugin resolves the matching Sentry sub-packages to an empty module so they're not included in the output bundle.


| Option | Default | Effect when set to `false` |
| ------------------ | ------- | ------------------------------------------------------------------------ |
| `includeWebReplay` | `true` | Excludes `@sentry/replay` and `@sentry-internal/replay` from the bundle. |
| `includeFeedback` | `true` | Excludes `@sentry-internal/feedback` from the bundle. |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may change includeFeedback to includeWebReplay if getsentry/sentry-react-native#6025 (comment) is accepted


Note that these options only affect bundling. They do not disable the corresponding native (Android/iOS) integrations.

```javascript {tabTitle:React Native} {filename:metro.config.js}
const { getDefaultConfig } = require("@react-native/metro-config");
const { withSentryConfig } = require("@sentry/react-native/metro");

const config = getDefaultConfig(__dirname);
module.exports = withSentryConfig(config, {
includeWebReplay: false,
includeFeedback: false,
});
```

```javascript {tabTitle:Expo} {filename:metro.config.js}
const { getSentryExpoConfig } = require("@sentry/react-native/metro");

const config = getSentryExpoConfig(__dirname, {
includeWebReplay: false,
includeFeedback: false,
});
```

### Wrap Your Custom Serializer

If you already have a custom serializer, you can wrap it with the Sentry Metro Serializer and call `options.sentryBundleCallback` before serializing the bundle content.
Expand Down
Loading