1.1.2 • Published 5 months ago

module-federation-vite v1.1.2

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

Vite plugin for Module Federation

npm

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

Vue

React

More examples here

pnpm install && pnpm run dev-vv # vite+vite dev demo
pnpm install && pnpm run preview-vv # vite+vite build demo

Getting started 🚀

https://module-federation.io/guide/basic/webpack.html

// vite.config.js
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { federation } from '@module-federation/vite';
import topLevelAwait from 'vite-plugin-top-level-await';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    federation({
      name: 'bbc',
      remotes: {
        mfapp01: 'mfapp01@https://unpkg.com/mf-app-01@1.0.9/dist/remoteEntry.js',
        remote2: 'mfapp02@https://unpkg.com/mf-app-02/dist/remoteEntry.js',
        remote3:
          'remote1@https://unpkg.com/react-manifest-example_remote1@1.0.6/dist/mf-manifest.json',
        // "remote4": {
        //   entry: "http://localhost:xxxx/remoteEntry.js",
        //   globalEntryName: "xxxx",
        //   type: "module"
        // }
      },
      exposes: {
        './App': './src/App.vue',
      },
      filename: 'remoteEntry-[hash].js',
      // https://github.com/module-federation/vite/issues/87
      manifest: true,
      shared: {
        vue: {},
        react: {
          requiredVersion: '18',
        },
      },
    }),
    // If you set build.target: "chrome89", you can remove this plugin
    // topLevelAwait(),
  ],
  server: {
    port: 5173,
    // dev mode please set origin
    origin: 'http://localhost:5173',
  },
  build: {
    target: 'chrome89',
  },
});

roadmap

  • feat: generate mf-manifest.json
  • feat: support chrome plugin
  • feat: support runtime plugins
  • feat: nuxt ssr
  • feat: download remote d.ts
  • feat: generate d.ts
  • feat: support @vitejs/plugin-legacy
  • feat: Another plugin, when only some remote modules are started, automatically completes HMR(#54)

So far so good 🎉

Now you are ready to use Module Federation in Vite!

1.2.0-test

5 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.1.2

9 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

11 months ago

1.0.9-beta.1

11 months ago

1.0.9-beta.0

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.4

11 months ago

1.0.3-beta.0

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago

0.9.7

11 months ago

0.9.6

11 months ago

0.9.5

11 months ago

0.9.4

11 months ago

0.9.3

11 months ago

0.9.2

11 months ago

0.9.1

11 months ago

0.9.0

11 months ago

0.0.15

11 months ago

0.0.14

11 months ago

0.0.13

11 months ago

0.0.12

11 months ago

0.0.11

11 months ago

0.0.10

11 months ago

0.0.9

11 months ago

0.0.8

11 months ago

0.0.7

11 months ago

0.0.6

11 months ago

0.0.5

11 months ago

0.0.3

11 months ago

0.0.2

11 months ago

0.0.1

11 months ago