# Rspack Plugin

:::info Note
Requires Rspack version 0.5.0 or above.
:::

- Capable of building modules that meet the `Module Federation` loading specifications.
- Can consume modules that adhere to the `Module Federation` specifications using aliases.
- Can set shared dependency configurations for modules, so that when the host environment of the loaded module already has the corresponding dependency, it will not be loaded again.
- When a module has remote types, it will automatically download and consume the types of the remote modules.
- Consuming remote modules will have hot update capabilities.

## Quick Start

### Installation

You can install the plugin with the following commands:

import { PackageManagerTabs } from '@theme';

<PackageManagerTabs
  command={{
    npm: `
npm add @module-federation/enhanced
    `,
    yarn: `
yarn add @module-federation/enhanced
    `,
    pnpm: `
pnpm add @module-federation/enhanced
    `,
    bun: `
bun add @module-federation/enhanced
    `,
  }}
/>

### Register the Plugin

#### Rspack

In [Rspack](https://rspack.dev/), you can add the plugin in the `rspack.config.js` file:

```ts title="rspack.config.js"
const { ModuleFederationPlugin } = require('@module-federation/enhanced/rspack');

module.exports = {
  devServer: {
    port: 2000,
  },
  output: {
    // You need to set a unique value that is not equal to other applications
    uniqueName: 'federation_provider',
    // publicPath must be configured if using manifest
    publicPath: 'http://localhost:2000/',
  },
  plugins: [
    new ModuleFederationPlugin({
      name: 'federation_provider',
      exposes: {
        './button': './src/button.tsx',
      },
      shared: ['react', 'react-dom'],
    }),
  ],
};
```

## Configure the Build Plugin

- Type: `ModuleFederationPlugin(options: ModuleFederationOptions)`

- The configuration structure for the Module Federation plugin is as follows:

```ts
type ModuleFederationOptions = {
  name: string;
  filename?: string;
  remotes?: Array<RemoteInfo>;
  shared?: ShareInfos;
};
```

You can find detailed explanations of all configuration items on the [Configuration Overview](../../configure/index) page.
