Rspack

  • Capable of building modules that meet the Module Federation carregamento specifications.
  • Can consume modules that adhere to the Module Federation specifications using aliases.
  • Can definir dependência compartilhada configurações for módulos, so esse quando o host environment do carregado módulo já has o corresponding dependência, it vai não ser carregado again.
  • Quando um módulo has remote tipos, it vai automatically download e consuma o tipos do módulos remotos.
  • Consuming módulos remotos vai have hot update capabilities.

Início rápido

Instalação

Você pode instale o plugin com o seguintes comandos:

npm
yarn
pnpm
bun
npm add @module-federation/enhanced

Crie module-federation.configuração.ts

Crie o module-federation.configuração.ts arquivo com o seguintes content:

module-federation.config.ts
import { createModuleFederationConfig } from '@module-federation/enhanced/rspack';

export default createModuleFederationConfig({
  name: 'host',
  remotes: {
    provider: 'provider@http://localhost:2004/mf-manifest.json',
  },
  exposes: {
    './Button': './src/components/Button.tsx',
  },
  shared: {
    react: {
      singleton: true,
    },
    'react-dom': {
      singleton: true,
    },
  },
});

Register Plugin

In Rspack, você pode add plugins por meio do plugins configuração item:

rspack.config.ts
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
import mfConfig from './module-federation.config';

export default defineConfig({
  plugins: [new ModuleFederationPlugin(mfConfig)],
});

Configuração

Você pode find detailed descriptions de all configuração items no Config Overview page.