Skip to content

feat: module federation#79

Merged
leegeunhyeok merged 4 commits into
mainfrom
feat/mf
May 19, 2026
Merged

feat: module federation#79
leegeunhyeok merged 4 commits into
mainfrom
feat/mf

Conversation

@leegeunhyeok

@leegeunhyeok leegeunhyeok commented May 6, 2026

Copy link
Copy Markdown
Member

Description

Module Federation v2 implementation

refs: https://module-federation.io

Preview

  • rollipop start --config rollipop.host.config.ts --port 8081
  • rollipop start --config rollipop.remote.config.ts --port 8082
// rollipop.host.config.ts
import { federation } from '@rollipop/plugin-module-federation';
import { defineConfig } from 'rollipop';

export default defineConfig({
  entry: 'src/host/index.ts',
  plugins: [
    federation({
      name: 'host_app',
      remotes: {
        remote_app: 'remote_app@http://localhost:8082/index.bundle',
      },
      shared: {
        react: { singleton: true, eager: true, requiredVersion: '19.2.3' },
        'react-native': { singleton: true, eager: true, requiredVersion: '0.84.1' },
        '@react-navigation/native': { singleton: true, eager: true },
        '@react-navigation/native-stack': { singleton: true, eager: true },
        'react-native-safe-area-context': { singleton: true, eager: true },
        'react-native-screens': { singleton: true, eager: true },
      },
    }),
  ],
});
// rollipop.remote.config.ts
import { federation } from '@rollipop/plugin-module-federation';
import { defineConfig } from 'rollipop';

export default defineConfig({
  entry: 'src/remote/index.ts',
  plugins: [
    federation({
      name: 'remote_app',
      exposes: {
        './RemoteNavigator': './src/remote/exposed/RemoteNavigator.tsx',
      },
      shared: {
        react: { singleton: true, requiredVersion: '19.2.3' },
        'react-native': { singleton: true, requiredVersion: '0.84.1' },
        '@react-navigation/native': { singleton: true },
        '@react-navigation/native-stack': { singleton: true },
        'react-native-safe-area-context': { singleton: true },
        'react-native-screens': { singleton: true },
      },
    }),
  ],
});
// Usage
const LazyRemoteNavigator = React.lazy(() =>
  import('remote_app/RemoteNavigator').then((module: Module) => ({
    default: module.default ?? module,
  })),
);

<Suspense fallback={...}>
  <LazyRemoteNavigator />
</Suspense>
Screen.Recording.2026-05-20.at.00.53.20.mov
Screenshot 2026-05-07 at 04 39 40

Comment on lines +38 to +49
// Federation remote runs inside a host that already initialized the React Native runtime.
// So we don't need to run the prelude and polyfills again.
serializer.prelude = [];
serializer.polyfills = [];

return {
dangerously_overrideRolldownOptions: (opts) => ({
input: opts.input,
// Output as IIFE — the bundle is a script that dynamically runs on the runtime.
output: { ...opts.output, format: 'iife' },
}),
};

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

important

map: ReturnType<MagicString['generateMap']>;
}

// TODO: To native plugin?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO

@leegeunhyeok leegeunhyeok merged commit 140902b into main May 19, 2026
1 check passed
@leegeunhyeok leegeunhyeok deleted the feat/mf branch May 19, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant