Skip to content

Commit 1f15086

Browse files
Add Custom Babel Transformers to Sentry Metro Plugin page (#12495)
Co-authored-by: Alex Krawiec <[email protected]>
1 parent ae675d9 commit 1f15086

File tree

1 file changed

+40
-5
lines changed
  • docs/platforms/react-native/manual-setup

1 file changed

+40
-5
lines changed

docs/platforms/react-native/manual-setup/metro.mdx

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: Metro
3-
description: "Learn about the Metro bundler and how to configure it for your your application with Sentry React Native SDK."
3+
description: "Learn about the Metro bundler and how to configure it for your application with Sentry React Native SDK."
44
sidebar_order: 3
55
---
66

7-
Sentry's React Native SDK package ships with a Sentry Metro Serializer which allows you to automatically generate Debug IDs for your applications' bundles. This is crucial for making source maps work properly with Sentry.
7+
Sentry's React Native SDK package ships with a Sentry Metro Plugin which allows you to automatically generate Debug IDs for your applications' bundles. This is crucial for making source maps work properly with Sentry. The plugin also helps you to annotate React component names so they are available in breadcrumbs and minimize the bundle size by removing unused SDK features.
88
This page will guide you through the process of setting up the Metro Plugin for your application.
99

1010
## Prerequisities
@@ -15,11 +15,11 @@ This page will guide you through the process of setting up the Metro Plugin for
1515

1616
## Configuration
1717

18-
The Sentry React Native SDK allows multiple ways to configure the Sentry Metro Serializer, depending on your current use of `customeSerializer` in your Metro configuration.
18+
The Sentry React Native SDK allows multiple ways to configure the Sentry Metro Plugin, depending on your current use of the Metro configuration.
1919

20-
### Use Sentry Metro Serializer
20+
### Use the Sentry Metro Plugin
2121

22-
The example below shows how to use the Sentry Metro Serializer if you don't have any `customSerializers` (the default configuration).
22+
The example below shows how to use the Sentry Metro Plugin with the default config.
2323

2424
```javascript {tabTitle:React Native} {filename:metro.config.js}
2525
const { getDefaultConfig } = require("@react-native/metro-config");
@@ -37,6 +37,41 @@ const { getSentryExpoConfig } = require("@sentry/react-native/metro");
3737
const config = getSentryExpoConfig(__dirname);
3838
```
3939

40+
### Add a Custom Babel Transformer
41+
42+
If you already have a custom transformer, ensure that the Sentry Metro Plugin is applied as the last step. The Sentry Metro Plugin doesn't overwrite the existing configuration, it extends or wraps existing properties.
43+
44+
```javascript {tabTitle:React Native} {filename:metro.config.js}
45+
const { getDefaultConfig } = require("@react-native/metro-config");
46+
const { withSentryConfig } = require('@sentry/react-native/metro');
47+
48+
const config = getDefaultConfig(__dirname);
49+
50+
config.transformer = {
51+
...config.transformer,
52+
babelTransformerPath: require.resolve('react-native-custom-transformer'),
53+
};
54+
55+
module.exports = withSentryConfig(config);
56+
```
57+
58+
```javascript {tabTitle:Expo} {filename:metro.config.js}
59+
const { getDefaultConfig } = require('@expo/metro-config');
60+
const { getSentryExpoConfig } = require('@sentry/react-native/metro');
61+
62+
const config = getSentryExpoConfig(__dirname, {
63+
getDefaultConfig: (projectRoot, options) => {
64+
const config = getDefaultConfig(projectRoot, options);
65+
66+
config.transformer = {
67+
...config.transformer,
68+
babelTransformerPath: require.resolve('react-native-custom-transformer/expo'),
69+
};
70+
return config;
71+
},
72+
});
73+
```
74+
4075
### Wrap Your Custom Serializer
4176

4277
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.

0 commit comments

Comments
 (0)