logologo
Guide
Practice
Configuration
Plugins
Showcase
Blog
Ecosystem
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
Guide
Practice
Configuration
Plugins
Showcase
Blog
Module Federation Examples
Practical Module Federation
Zephyr Cloud
Nx
简体中文
English
logologo
Overview

Bridge

Bridge Overview

React Bridge

Getting Started
Export Application
Load Remote Application
Load Remote Component
Vue Bridge

Frameworks

Framework Overview

React

Basic CRA with Rsbuild
Using Nx CLI for React
Internationalization (i18n)

Modern.js

Quick Start
Dynamic load provider

Next.js

Basic Example
Importing Components
Routing & Importing Pages
Working with Express.js
Presets

Angular

Angular CLI Setup
Using Nx CLI for Angular
Micro-frontends with Angular
Server-Side Rendering
Using Service Workers
Authentication with Auth0
Authentication with Okta
Splitting a Monolith
Extending a Monolith
Edit this page on GitHub
Previous PageLoad Remote Component
Next PageFramework Overview

#Vue Bridge (for Vue v3)

@module-federation/bridge-vue3 provides a bridge utility function for Vue V3 applications. The provided createBridgeComponent can be used to export application-level modules, and createRemoteAppComponent can be used to load application-level modules.

#Installation

npm
yarn
pnpm
npm install @module-federation/bridge-vue3@latest

#Type

function createRemoteAppComponent<T, E extends keyof T>(
  options: {
    // Function to load remote application, e.g., loadRemote('remote1/export-app') or import('remote1/export-app')
    loader: () => Promise<T>;
    // Default is 'default', used to specify module export
    export?: E;
    // Parameters that will be passed to defineAsyncComponent
    asyncComponentOptions?: Omit<AsyncComponentOptions, 'loader'>;
    // Attributes that will be bound to the root container where the remote Vue application will be mounted
    rootAttrs?: Record<string, unknown>;
  }
): (props: {
    basename?: string;
    memoryRoute?: { entryPath: string };
}) => DefineComponent;


function createBridgeComponent(bridgeInfo: {
  rootComponent: VueComponent;
  appOptions?: (params: {
    app: Vue.App<VueComponent>;
    basename?: string;
    memoryRoute?: { entryPath: string };
    [key: string]: any;
  }) => { router?: Router } | void;
}): () => {
  render(info: {
    name?: string;
    basename?: string;
    memoryRoute?: {
      entryPath: string;
    };
    dom?: HTMLElement;
  }): void;
  destroy(info: {
    dom: HTMLElement;
  }): void;
}

#Example

Remote

// ./src/export-app.ts
import App from './App.vue';
import router from './router';
import customPlugin from './plugins/custom-vue-plugin';
import { createBridgeComponent } from '@module-federation/bridge-vue3';

export default createBridgeComponent({
  rootComponent: App,
  appOptions: ({app}) => {
    // Optional: adding a plugin to the new Vue instance on the host application side
    app.use(customPlugin);
    return { router };
  },
});
// rsbuild.config.ts
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';

export default defineConfig({
  plugins: [
    pluginModuleFederation({
      name: 'remote1',
      exposes: {
        './export-app': './src/export-app.ts',
      },
      shared: ['vue', 'vue-router'],
    }),
  ],
});

Host

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

export default defineConfig({
  plugins: [
    pluginModuleFederation({
      name: 'host',
      remotes: {
        remote1: 'remote1@http://localhost:2001/mf-manifest.json',
      },
    }),
  ],
});
// ./src/router.ts
import * as bridge from '@module-federation/bridge-vue3';

const Remote2 = bridge.createRemoteAppComponent({ loader: () => loadRemote('remote1/export-app'), rootAttrs: {class: 'root-element-class'} });

const router = createRouter({
  history: createWebHistory(),
  routes: [
    // Define your routes here
    { path: '/', component: Home },
    { path: '/remote1/:pathMatch(.*)*', component: Remote2, props: { foo: 'bar' } },
    // Other routes
  ],
});
export default router;

#Parameters

#createRemoteAppComponent

function createRemoteAppComponent<T, E extends keyof T>(
  options: {
    // Function to load remote application, e.g., loadRemote('remote1/export-app') or import('remote1/export-app')
    loader: () => Promise<T>;
    // Default is 'default', used to specify module export
    export?: E;
    // Parameters that will be passed to defineAsyncComponent
    asyncComponentOptions?: Omit<AsyncComponentOptions, 'loader'>;
    // Attributes that will be bound to the root container where the remote Vue application will be mounted
    rootAttrs?: Record<string, unknown>;
  }
): (props: {
    basename?: string;
    memoryRoute?: { entryPath: string };
}) => DefineComponent;
const Remote1App = createRemoteAppComponent({ loader: () => loadRemote('remote1/export-app') });
  • options
    • loader
      • type: () => Promise<Module>
      • Purpose: Used to load remote modules, e.g., loadRemote('remote1/export-app') or import('remote1/export-app')
    • export
      • type: string
      • Purpose: Used to specify module export
    • asyncComponentOptions
      • type: Omit<AsyncComponentOptions, 'loader'>
      • Purpose: Parameters that will be passed to defineAsyncComponent, except for the loader parameter
    • rootAttrs
      • type: Record<string, unknown>
      • Purpose: Attributes that will be bound to the root container where the remote Vue application will be mounted
// remote
export const provider = createBridgeComponent({
  rootComponent: App
});

// host
const Remote1App = createRemoteAppComponent({
  loader: () => loadRemote('remote1/export-app'),
  export: 'provider'
});
  • ReturnType
    • type: VueComponent
    • Purpose: Used to render remote module components
import * as bridge from '@module-federation/bridge-vue3';

const Remote2 = bridge.createRemoteAppComponent({ loader: () => loadRemote('remote1/export-app'), rootAttrs: {class: 'root-element-class'} });

const router = createRouter({
  history: createWebHistory(),
  routes: [
    // Define your routes here
    { path: '/', component: Home },
    { path: '/remote1/:pathMatch(.*)*', component: Remote2, props: { foo: 'bar' } },
    // Other routes
  ],
});
export default router;

#createBridgeComponent

function createBridgeComponent(bridgeInfo: {
  rootComponent: VueComponent;
  appOptions?: (params: {
    app: Vue.App<VueComponent>;
    basename?: string;
    memoryRoute?: { entryPath: string };
    [key: string]: any;
  }) => { router?: Router } | void;
}): () => {
  render(info: {
    name?: string;
    basename?: string;
    memoryRoute?: {
      entryPath: string;
    };
    dom?: HTMLElement;
  }): void;
  destroy(info: { dom: HTMLElement }): void;
}
  • bridgeInfo
    • type: { rootComponent: VueComponent; appOptions?: (params: AddOptionsFnParams) => ({ router?: Router }) }
    • Purpose: Used to pass the root component
  • ReturnType
    • type: () => { render: (info: RenderFnParams) => void; destroy: (info: { dom: HTMLElement}) => void; }
// ./src/export-app.ts
import  { createBridgeComponent } from '@module-federation/bridge-vue3';
import App from './App.vue';
import customPlugin from './plugins/custom-vue-plugin';
import router from './router';

export default createBridgeComponent({
  rootComponent: App,
  appOptions: ({app}) => {
    // Optional: adding a plugin to the new Vue instance on the host application side
    app.use(customPlugin)
    return { router };
  },
});