Skip to content

Latest commit

 

History

History
67 lines (45 loc) · 2.24 KB

File metadata and controls

67 lines (45 loc) · 2.24 KB

Nuxt Module Federation host example

This Nuxt application demonstrates local and federated server-rendered Vue components.

Run both applications

From the repository root:

pnpm install
pnpm dev

Open http://localhost:4173. The page should contain the host card, host SSR component, remote widget, and remote SSR component.

To run only the host:

pnpm dev:host

The remote must already be reachable on port 4174 for manifest discovery and remote rendering.

Federation wiring

nuxt.config.ts:

  • registers @module-federation/nuxt;
  • maps the MF remote name remote to http://localhost:4174/mf-manifest.json;
  • lists Counter and Widget in remoteComponents, keeping registration deterministic if the remote manifest is unavailable during setup;
  • exposes them as <RemoteCounter /> and <RemoteWidget /> through Nuxt auto-imports.

The page consumes it like any other Nuxt component:

<template>
  <HostCard />
  <HostSsrComponent />
  <RemoteWidget />
  <RemoteCounter />
</template>

Bridge application remote

/bridge/* mounts remote/bridge/export-app via @module-federation/bridge-vue3 (createRemoteAppComponent) as a client-only island. Component federation on / is unchanged. The host registers a Vue Router catch-all (/bridge/:pathMatch(.*)*) so basename auto-detect works with current bridge-vue3 releases.

SSR behavior

Nuxt 4.5 runs development with Vite 8 and Rolldown. Remote components render on the server during pnpm dev, then hydrate and remain interactive in the browser.

Production builds render the remote components on the server. Verify that path from the repository root:

pnpm build
pnpm preview

View the HTML source at http://localhost:4173 and confirm it contains Rendered by host before client hydration. and Rendered by remote before client hydration. Then confirm all counters remain interactive in the browser.

The preview ports are fixed. Stop any existing process on 4173 or 4174 before starting the examples.