|
| 1 | +# Rsbuild Plugin |
| 2 | + |
| 3 | +Help users quickly build Module Federation products in **Rsbuild App** or **Rslib** |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +### Installation |
| 8 | + |
| 9 | +You can install the plugin using the following command: |
| 10 | + |
| 11 | +import { PackageManagerTabs } from '@theme'; |
| 12 | + |
| 13 | +<PackageManagerTabs |
| 14 | + command={{ |
| 15 | + npm: 'npm add @module-federation/rsbuild-plugin --save-dev', |
| 16 | + yarn: 'yarn add @module-federation/rsbuild-plugin --save-dev', |
| 17 | + pnpm: 'pnpm add @module-federation/rsbuild-plugin --save-dev', |
| 18 | + bun: 'bun add @module-federation/rsbuild-plugin --save-dev', |
| 19 | + }} |
| 20 | +/> |
| 21 | + |
| 22 | +### Register plugin |
| 23 | +#### Rsbuild App |
| 24 | +```ts title='rsbuild.config.ts' |
| 25 | +import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'; |
| 26 | +import { defineConfig } from '@rsbuild/core'; |
| 27 | +import { pluginReact } from '@rsbuild/plugin-react'; |
| 28 | + |
| 29 | +export default defineConfig({ |
| 30 | + server: { |
| 31 | + port: 2000, |
| 32 | + }, |
| 33 | + plugins: [ |
| 34 | + pluginReact(), |
| 35 | + pluginModuleFederation({ |
| 36 | + name: 'federation_consumer', |
| 37 | + remotes: { |
| 38 | + remote1: 'remote1@http://localhost:2001/mf-manifest.json', |
| 39 | + }, |
| 40 | + shared: ['react', 'react-dom'], |
| 41 | + }), |
| 42 | + ], |
| 43 | +}); |
| 44 | +``` |
| 45 | + |
| 46 | +#### Rslib Module |
| 47 | +``` ts title='rslib.config.ts' |
| 48 | +import { pluginModuleFederation } from '@module-federation/rsbuild-plugin'; |
| 49 | +import { defineConfig } from '@rslib/core'; |
| 50 | + |
| 51 | +export default defineConfig({ |
| 52 | + lib: [ |
| 53 | + // ... |
| 54 | + { |
| 55 | + format: 'mf', |
| 56 | + output: { |
| 57 | + distPath: { |
| 58 | + root: './dist/mf', |
| 59 | + }, |
| 60 | + assetPrefix: 'xxx', |
| 61 | + }, |
| 62 | + plugins: [ |
| 63 | + // ... |
| 64 | + pluginModuleFederation({ |
| 65 | + name: 'rslib_provider', |
| 66 | + exposes: { |
| 67 | + '.': './src/index.tsx', |
| 68 | + }, |
| 69 | + shared: { |
| 70 | + react: { |
| 71 | + singleton: true, |
| 72 | + }, |
| 73 | + 'react-dom': { |
| 74 | + singleton: true, |
| 75 | + }, |
| 76 | + }, |
| 77 | + }), |
| 78 | + ], |
| 79 | + }, |
| 80 | + ], |
| 81 | +}); |
| 82 | +``` |
| 83 | + |
| 84 | +### Note |
| 85 | +If you need to use the Module Federation runtime capabilities, please install [@module-federation/enhanced](/en/guide/basic/runtime.html) |
0 commit comments