npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@module-federation/vite

v1.19.1

Published

Vite plugin for Module Federation

Readme

Vite plugin for Module Federation

npm

Vite and VoidZero recommend this plugin

Read the announcement.

Become a sponsor

Support this project on GitHub Sponsors

Reason why 🤔

Microservices nowadays is a well-known concept and maybe you are using it in your current company. Do you know that now you can apply similar ideas on the Frontend? With Module Federation you can load separately compiled and deployed code into a unique application. This plugin makes Module Federation work together with Vite.

Working implementations

Examples live in gioboa/module-federation-vite-examples:

| Example | Host | Remote | Framework | | ---------------------------------------------------------------------------------------- | --------------- | ----------------- | --------------------------- | | Alpine | alpine-host | alpine-remote | Alpine.js | | Angular | angular-host | angular-remote | Angular | | Astro | astro-host | astro-remote | Astro 7 | | Ember | ember-host | ember-remote | Ember 7 | | Lit | lit-host | lit-remote | Lit | | Nuxt | nuxt-host | nuxt-remote | Nuxt 4 | | Nx | host | remote | React + Nx | | Preact | preact-host | preact-remote | Preact 10 | | React | react-host | react-remote | React 19 | | Solid | solid-host | solid-remote | Solid | | Svelte | svelte-host | svelte-remote | Svelte 5 | | TanStack | tanstack-host | tanstack-remote | TanStack Router + React 19 | | Turborepo | host | remote | React + Turborepo | | Vinext | vinext-host | vinext-remote | Vinext + Next 16 + React 19 | | Vue | vue-host | vue-remote | Vue 3 |

Try this crazy example with all these bundlers together

pnpm install
pnpm run build
pnpm run multi-example

Getting started 🚀

https://module-federation.io/integrations/build-tool/vite

With @module-federation/vite, the process becomes delightfully simple, you will only find the differences from a normal Vite configuration.

This example is with Vue.js The @module-federation/vite configuration remains the same for different frameworks.

Migrating from OriginJS

Migrating from @originjs/vite-plugin-federation requires an explicit remote-entry format and runtime review, particularly for dynamic remotes, shared dependencies, and mixed bundlers. See the OriginJS migration guide for step-by-step migration and incremental deployment guidance.

Dedicated configuration file

You can keep Module Federation options in module-federation.config.ts.

import { createModuleFederationConfig } from "@module-federation/vite";

export default createModuleFederationConfig({
  name: "remote",
  filename: "remoteEntry.js",
  exposes: {
    "./remote-app": "./src/App.vue",
  },
  shared: ["vue"],
});
import { defineConfig } from "vite";
import { federation } from "@module-federation/vite";
import moduleFederationConfig from "./module-federation.config";

export default defineConfig({
  plugins: [federation(moduleFederationConfig)],
});

The Remote Application configuration

file: remote/vite.config.ts

import { defineConfig } from 'vite';
import { federation } from '@module-federation/vite'; 👈

export default defineConfig({
  [...]
  plugins: [
    [...]
    federation({ 👈
      name: "remote",
      filename: "remoteEntry.js",
      // optional: additional "var" remoteEntry file
      // needed only for legacy hosts with "var" usage (remote.type = 'var')
      varFilename: "varRemoteEntry.js",
      exposes: {
        "./remote-app": "./src/App.vue",
      },
      shared: ["vue"],
    }),
  ],
  server: {
    origin: "http://localhost:{Your port}"
  },
  [...]
});

In this remote app configuration, we define a remoteEntry.js file that will expose the App component. The shared property ensures that both host and remote applications use the same vue library.

The Host Application configuration

file host/vite.config.ts

import { defineConfig } from 'vite';
import { federation } from '@module-federation/vite'; 👈

export default defineConfig({
  [...]
  plugins: [
    [...]
    federation({ 👈
      name: "host",
      remotes: {
        remote: {
          type: "module", // type "var" (default) for vite remote is supported with remote's `varFilename` option
          name: "remote",
          entry: "https://[...]/remoteEntry.js",
          entryGlobalName: "remote",
          shareScope: "default",
        },
      },
      filename: "remoteEntry.js",
      shared: ["vue"],
      // Optional parameter that controls where the host initialization script is injected.
      // By default, it is injected into the index.html file.
      // You can set this to "entry" to inject it into the entry script instead.
      // Recommended for SSR hosts without index.html (Nitro, TanStack Start) so
      // initHost() completes before hydrateRoot and @module-federation/bridge-react
      // remotes render on first paint.
      hostInitInjectLocation: "html", // or "entry"
      // Controls whether all CSS assets from the bundle should be added to every exposed module.
      // When false (default), the plugin will not process any CSS assets.
      // When true, all CSS assets are bundled into every exposed module.
      bundleAllCSS: false, // or true
      // Timeout for parsing modules in seconds.
      // Defaults to 10 seconds.
      moduleParseTimeout: 10,
      // Idle timeout for parsing modules in seconds. When set, the timeout
      // resets on every parsed module and only fires when there has been no
      // module activity for the configured duration. Prefer this over
      // moduleParseTimeout for large codebases where total build time may
      // exceed the fixed timeout value.
      moduleParseIdleTimeout: 10,
      // Controls whether module federation manifest artifacts are generated.
      // Type: boolean | object
      // - false/undefined: no manifest generated
      // - true: generates mf-manifest.json + mf-stats.json (default names)
      // - object: overrides fileName/filePath and asset analysis behavior
      manifest: {
        // Optional output file name for runtime manifest.
        // Default: "mf-manifest.json"
        fileName: "mf-manifest.json",
        // Optional output directory/path for both artifacts.
        // Example: "dist/" -> dist/mf-manifest.json + dist/mf-stats.json
        filePath: "dist/",
        // If true, skips asset analysis.
        // Effect: shared/exposes are omitted from manifest and assetAnalysis is omitted from stats.
        // It also disables the preload-helper patch used for remotes.
        // In serve for consumer-only apps, this defaults to true unless explicitly set.
        disableAssetsAnalyze: false,
        // Optional hook to mutate generated manifest/stats data.
        additionalData: ({ stats }) => {
          stats.metaData.deployEnv = process.env.NODE_ENV;
          stats.metaData.region = "eu";
          stats.custom = {
            buildId: process.env.BUILD_ID,
          };
        },
        // Or return a replacement/merged object.
        // additionalData: ({ stats }) => ({
        //   ...stats,
        //   custom: { buildId: process.env.BUILD_ID },
        // }),
      },
    }),
  ],
  server: {
    origin: "http://localhost:{Your port}"
  },
  [...]
});

The host app configuration specifies its name, the filename of its exposed remote entry remoteEntry.js, and importantly, the configuration of the remote application to load. You can specify the place the host initialization file is injected with the hostInitInjectLocation option, which is described in the example code above. The moduleParseTimeout option allows you to configure the maximum time to wait for module parsing during the build process. The moduleParseIdleTimeout option is an alternative that resets the timer on every parsed module. It only fires when there has been no module activity for the configured duration, making it suitable for large codebases where the total build time exceeds the fixed timeout.

Runtime capability optimization

Runtime features that a build never uses can be removed at build time:

federation({
  name: "remote",
  exposes: {
    "./remote-app": "./src/App.vue",
  },
  disableRemote: true,
  disableShared: true,
  disableSnapshot: true,
});
  • disableRemote removes remote-consumption support. Do not enable it when remotes are configured.
  • disableShared removes shared-dependency support. Do not enable it when shared dependencies are configured.
  • disableSnapshot removes snapshot support, including manifest-based remotes, preload, dynamic type hints, HMR, and devtools integration.

All three options default to false, except disableSnapshot, which defaults to true for Node/SSR builds. An explicitly configured Vite define value takes precedence over the corresponding option.

Load the Remote App

In your host app, you can now import and use the remote app with defineAsyncComponent

file host/src/App.vue

<script setup lang="ts">
import { defineAsyncComponent } from "vue";
const RemoteMFE = defineAsyncComponent( 👈
  () => import("remote/remote-app")
);
</script>

<template>
  <RemoteMFE v-if="!!RemoteMFE" /> 👈
</template>

Shared Tree Shaking

Shared Tree Shaking reduces shared dependency bundles to the exports used by the application.

federation({
  shared: {
    antd: {
      singleton: true,
      treeShaking: {
        mode: "runtime-infer", // or "server-calc"
        usedExports: ["Button", "Input"],
      },
    },
  },
  treeShakingDir: "independent-packages",
});

runtime-infer is useful for local development and falls back to the full dependency when the required exports are not available. server-calc is recommended for deployments because it can use aggregated export metadata from all consumers.

Do not combine eager: true with treeShaking; eager shared dependencies are bundled into the initial entry and cannot use the on-demand tree-shaking path. Choose eager loading for small dependencies, or tree shaking for larger dependencies such as component libraries.

With server-calc, the Vite build records the exports used by each application in its generated Module Federation metadata. A deployment service must then collect that metadata for all applications that share the same dependency and version, merge their usedExports lists, and use the resulting union to create one optimized secondary shared artifact. For example, if one application uses Button and another uses Input, the secondary artifact must contain both exports.

After creating the secondary artifact, the deployment service must publish it to a location accessible by consumers, such as a CDN, and update the remote Snapshot with the artifact's URL, unique name, and available tree-shaking status. Consumers use those Snapshot fields to decide whether the optimized artifact can satisfy their required exports and version.

This deployment step is separate from the local Vite build; the plugin only emits the metadata and runtime support needed by the service. If the Snapshot is not updated, the artifact cannot be fetched, the versions do not match, or the artifact does not provide all required exports, the runtime ignores the optimized artifact and safely loads the complete shared dependency instead.

⚠️ codeSplitting settings are controlled by the plugin

Do not set either build.rollupOptions.output.codeSplitting or build.rolldownOptions.output.codeSplitting to false with this plugin — it will be automatically ignored.

codeSplitting.groups is also ignored because grouping shared-runtime chunks can break MF init order. Module Federation needs loadShare and runtimeInitStatus isolated into separate chunks for correct bootstrap behavior.

⚠️ manualChunks is not supported

Do not use build.rollupOptions.output.manualChunks or build.rolldownOptions.output.manualChunks with this plugin — it will be automatically ignored. The plugin manages the runtime chunk graph itself, and forcing custom chunk grouping can break Module Federation bootstrap order. The plugin injects the splits it needs so runtimeInitStatus and loadShare stay isolated.

So far so good 🎉

Now you are ready to use Module Federation in Vite!