Skip to content

feat(metro-serializer-esbuild): Enhance configurability of metro-serializer-esbuild#4009

Draft
JasonVMo wants to merge 5 commits intomainfrom
user/jasonvmo/serializer-configuration
Draft

feat(metro-serializer-esbuild): Enhance configurability of metro-serializer-esbuild#4009
JasonVMo wants to merge 5 commits intomainfrom
user/jasonvmo/serializer-configuration

Conversation

@JasonVMo
Copy link
Collaborator

@JasonVMo JasonVMo commented Mar 5, 2026

Description

This is a precursor change for adding the ability to have esbuild handle front-end transformation in addition to serialization. For this to happen, the serializer and transformer steps need to be configured together. To make that change easier this PR does the following:

  • Adds a broader configuration that will be used to configure both the serializer and transformer for metro bundling.
  • Made the transformer config be producable via a configuration function based on passed in options.
  • Moved the constant transformer config to be produced by this function.
  • Added a factory called MetroEsbuildFactory that is called with a configuration and returns makeSerializer and makeTransformer functions.
  • Added a setting that will switch who is responsible for minification, this will be extended when the transformer comes in so we can play with different options.

@github-actions github-actions bot added the feature: metro This is related to Metro label Mar 5, 2026
Copy link
Member

@tido64 tido64 left a comment

Choose a reason for hiding this comment

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

I am going to have to reject this change and here is why:

  1. The configuration provided by this plugin are required for esbuild to function at all. We cannot modify any of them. This is why all the tests are failing.
  2. The problem with this configuration is that it also breaks Metro's dev server. If you want tree shaking, use this serializer and the provided configuration. Otherwise, use none of them.
  3. This is why we encourage using @rnx-kit/cli. It does all of this behind the scenes.
  4. If you know what you're doing and want to make changes anyway, you should use the spread operator instead. There is no need for a factory pattern here.
    module.exports = makeMetroConfig({
      serializer: {
        customSerializer: MetroSerializer(),
      },
      transformer: {
        ...esbuildTransformerConfig,
        babelTransformerPath: require.resolve('react-native-svg-transformer'),
      },
    });

@JasonVMo
Copy link
Collaborator Author

JasonVMo commented Mar 6, 2026

I am going to have to reject this change and here is why:

  1. The configuration provided by this plugin are required for esbuild to function at all. We cannot modify any of them. This is why all the tests are failing.
  2. The problem with this configuration is that it also breaks Metro's dev server. If you want tree shaking, use this serializer and the provided configuration. Otherwise, use none of them.
  3. This is why we encourage using @rnx-kit/cli. It does all of this behind the scenes.
  4. If you know what you're doing and want to make changes anyway, you should use the spread operator instead. There is no need for a factory pattern here.
    module.exports = makeMetroConfig({
      serializer: {
        customSerializer: MetroSerializer(),
      },
      transformer: {
        ...esbuildTransformerConfig,
        babelTransformerPath: require.resolve('react-native-svg-transformer'),
      },
    });
    

I added the transformer code so you can see what that looks like. I will make a separate package for the transformer but I'm using this to test it in fluentui-react-native as the bundle time shot way up when bundling from typescript instead of JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature: metro This is related to Metro

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants