Rslib

Rslib pode use @module-federation/rsbuild-plugin para build Module Federation producers. It é uma good fit quando um componente library, business módulo, ou SSR producer precisa ser published as um independent artifact for other apps para consuma.

Início rápido

Instalação

npm
yarn
pnpm
bun
npm add @module-federation/rsbuild-plugin --save-dev

Register Plugin

rslib.config.ts
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
import { defineConfig } from '@rslib/core';

export default defineConfig({
  lib: [
    {
      format: 'mf',
      output: {
        distPath: {
          root: './dist/mf',
        },
        assetPrefix: 'https://example.com/mf/',
      },
      plugins: [
        pluginModuleFederation({
          name: 'rslib_provider',
          exposes: {
            '.': './src/index.tsx',
          },
          shared: {
            react: {
              singleton: true,
            },
            'react-dom': {
              singleton: true,
            },
          },
        }),
      ],
    },
  ],
});

SSR

Se você precisa build both navegador e Node.js artifacts, use target: 'dual' no plugin opções.

rslib.config.ts
pluginModuleFederation(
  {
    name: 'rslib_provider',
    exposes: {
      '.': './src/index.tsx',
    },
  },
  {
    target: 'dual',
  },
);

For all plugin opções, continue com Rsbuild plugin configuração.