0.15.0 • Published 6 months ago

@module-federation/bridge-react-webpack-plugin v0.15.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Bridge

React bridge is used to load the routing module in mf, so that the routing module can work properly with the host environment.

When to use

  • Load the route module
  • Load across the front end framework

How to use

1. Install the react bridge library

pnpm add @module-federation/bridge-react

2. Configure the react bridge library

Use createBridgeComponent create component provider

// ./src/index.tsx
import { createBridgeComponent } from '@module-federation/bridge-react';

function App() {
  return ( <BrowserRouter basename="/">
    <Routes>
      <Route path="/" Component={()=> <div>Home page</div>}>
      <Route path="/detail" Component={()=> <div>Detail page</div>}>
    </Routes>
  </BrowserRouter>)
}

export default createBridgeComponent({
  rootComponent: App
});

set alias to proxy

//rsbuild.config.ts
export default defineConfig({
  source: {
    alias: {
      'react-router-dom$': path.resolve(
        __dirname,
        'node_modules/@module-federation/bridge-react/dist/router.es.js',
      ),
    },
  },
  server: {
    port: 2001,
    host: 'localhost',
  },
  dev: {
    assetPrefix: 'http://localhost:2001',
  },
  tools: {
    rspack: (config, { appendPlugins }) => {
      delete config.optimization?.splitChunks;
      config.output!.uniqueName = 'remote1';
      appendPlugins([
        new ModuleFederationPlugin({
          name: 'remote1',
          exposes: {
            './export-app': './src/index.tsx',
          }
        }),
      ]);
    },
  },
});

3. Load the module with routing

//rsbuild.config.ts
export default defineConfig({
  tools: {
    rspack: (config, { appendPlugins }) => {
      config.output!.uniqueName = 'host';
      appendPlugins([
        new ModuleFederationPlugin({
          name: 'host',
          remotes: {
            remote1: 'remote1@http://localhost:2001/mf-manifest.json',
          },
        }),
      ]);
    },
  },
});

Use the module

// ./src/index.tsx
import { createBridgeComponent } from '@module-federation/bridge-react';

const Remote1 = createBridgeComponent(()=> import('remote1/export-app'));

function App() {
  return ( <BrowserRouter basename="/">
    <ul>
      <li>
        <Link to="/">
          Home
        </Link>
      </li>
      <li>
        <Link to="/remote1">
          Remote1
        </Link>
      </li>
    </ul>
    <Routes>
      <Route path="/" Component={()=> <div>Home page</div>}>
      <Route path="/remote1" Component={()=> <Remote1 />}>
    </Routes>
  </BrowserRouter>)
}

const root = ReactDOM.createRoot(document.getElementById('root')!);
root.render(
    <App />
);
0.8.9

11 months ago

0.8.8

12 months ago

0.8.5

1 year ago

0.8.4

1 year ago

0.8.7

12 months ago

0.8.6

12 months ago

0.7.2

1 year ago

0.7.1

1 year ago

0.7.3

1 year ago

0.7.0

1 year ago

0.10.0

10 months ago

0.8.1

1 year ago

0.8.0

1 year ago

0.8.3

1 year ago

0.8.2

1 year ago

0.7.6

1 year ago

0.7.5

1 year ago

0.7.7

1 year ago

0.13.0

8 months ago

0.13.1

8 months ago

0.14.0

7 months ago

0.14.1

7 months ago

0.14.2

7 months ago

0.14.3

7 months ago

0.11.0

9 months ago

0.11.1

9 months ago

0.11.2

9 months ago

0.11.3

9 months ago

0.11.4

9 months ago

0.9.0

10 months ago

0.9.1

10 months ago

0.12.0

8 months ago

0.8.12

10 months ago

0.8.11

10 months ago

0.8.10

11 months ago

0.15.0

7 months ago

0.6.16

1 year ago

0.6.15

1 year ago

0.6.14

1 year ago

0.6.13

1 year ago

0.6.12

1 year ago

0.6.11

1 year ago

0.6.7

1 year ago

0.6.9

1 year ago

0.6.8

1 year ago

0.6.10

1 year ago

0.6.6

1 year ago

0.6.5

1 year ago

0.6.4

1 year ago

0.6.3

1 year ago

0.6.2

1 year ago

0.6.1

1 year ago

0.6.0

1 year ago

0.5.2

1 year ago

0.5.1

1 year ago

0.5.0

1 year ago

0.4.0

1 year ago

0.3.5

1 year ago

0.3.4

1 year ago

0.3.3

1 year ago

0.3.2

1 year ago

0.3.1

1 year ago

0.3.0

1 year ago

0.2.8

1 year ago

0.2.7

1 year ago

0.2.6

1 year ago

0.2.5

1 year ago

0.2.4

1 year ago

0.2.3

1 year ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago