DEV Community

Navnit Rai
Navnit Rai

Posted on

Microfrontend using vuejs

In 2026, the "frontend monolith" is becoming a thing of the past for enterprise-scale applications. As teams grow, the ability to deploy features independently—without waiting for a 20-minute build of the entire system—is no longer a luxury; it’s a requirement.

In this guide, we’ll explore how to build a scalable Microfrontend (MFE) architecture using Vue 3, Vite, and Module Federation.

What are Microfrontends?

Microfrontends bring the microservices philosophy to the browser. Instead of one massive Vue application, you break your UI into smaller, self-contained apps that are composed at runtime.

Why use them?

  • Independent Deployments: Team A can update the "Checkout" module without touching Team B's "Product Catalog."
  • Technology Agnostic: While we’re focusing on Vue, different modules could theoretically use different versions of Vue or even different frameworks.
  • Faster Build Times: You only build and test the module you changed. The Tech Stack: Vite + Module Federation

While Webpack 5 pioneered Module Federation, in 2026, Vite is the go-to for Vue developers due to its insane speed. We’ll use vite-plugin-federation to bridge the gap.
The Architecture

  • Host (The Shell): The main container that handles routing and global state.

  • Remote (The Microapp): A standalone Vue app that "exposes" specific components or entire pages.
    Step 1: Setting Up the Remote App
    Imagine we are building a User Dashboard microfrontend.

  • Create the project:
    npm create vite@latest dashboard-mfe -- --template vue
    cd dashboard-mfe
    npm install @originjs/vite-plugin-federation --save-dev

  • Configure vite.config.js:
    You need to tell Vite which components to "expose" to the outside world.
    import { defineConfig } from 'vite';
    import vue from '@vitejs/plugin-vue';
    import federation from '@originjs/vite-plugin-federation';

export default defineConfig({
plugins: [
vue(),
federation({
name: 'dashboard_app',
filename: 'remoteEntry.js',
exposes: {
'./Dashboard': './src/components/Dashboard.vue',
},
shared: ['vue'], // Share Vue to avoid loading it twice
}),
],
build: {
target: 'esnext', // Required for module federation
},
});

Step 2: Setting Up the Host (Shell)
The Host is the "parent" app that will consume the Dashboard component.

  • Configure vite.config.js in the Host:
    We define where the remote app is located.
    federation({
    name: 'host_app',
    remotes: {
    dashboard: 'http://localhost:5001/assets/remoteEntry.js',
    },
    shared: ['vue'],
    })

  • Consume the Remote Component:
    In your Host's Vue files, you can now import the remote component as if it were local.
    <br> import { defineAsyncComponent } from &#39;vue&#39;;</p></li> </ul> <p>// Lazy load the remote component<br> const RemoteDashboard = defineAsyncComponent(() =&gt; import(&#39;dashboard/Dashboard&#39;));<br>



    Shell Navigation


    Best Practices for 2026

    1. State Management (Pinia) Don't try to share a single global Pinia store across all MFEs. This creates tight coupling. Instead:
      • Remotes should have their own local stores.
      • Communication should happen via Custom Events or a lightweight Event Bus.
    2. Versioning and Deployment
      Always use a Blue/Green deployment strategy for your remotes. Since the Host fetches the remoteEntry.js at runtime, a broken remote can take down the UI. Use Error Boundaries in Vue to catch loading failures:




      Loading Dashboard...


    3. CSS Isolation
      Use CSS Modules or Scoped Styles () religiously. In a microfrontend world, a global .btn class in your Auth MFE can accidentally ruin the styling of your Dashboard MFE.<br> Summary Table: Vite vs. Single-SPA<br> | Feature | Vite + Module Federation | Single-SPA |<br> |---|---|---|<br> | Ease of Use | High (Plugin-based) | Medium (High Boilerplate) |<br> | Performance | Native ESM (Fastest) | SystemJS (Slight Overhead) |<br> | Best For | Pure Vue/Modern Stacks | Heterogeneous Stacks (Angular + Vue + React) |<br> Microfrontends aren&#39;t a silver bullet—they add operational complexity. But for large teams, the trade-off in developer velocity is almost always worth it.<br> Would you like me to generate a complete boilerplate repository structure for this setup?</p></li> </ol>

Top comments (0)