Vite is the first build tool Zephyr is able to handle Module Federation configuration directly, although you can still use the official Vite Plugin from Module Federation. Both cases are supported in this guide.
This guide aims to walk you through how you can deploy a Micro-Frontend application using the Official Vite Plugin from Module Federation. After this guide, you will have a React application consuming remote applications bundled by Vite, Rspack and Webpack deployed through Zephyr Cloud.
For applications built with Vite:
For applications built with Webpack and Rspack:
Four example build configuration for Vite, Rspack and Webpack.
For your host application, you can use withZephyr() from vite-plugin-zephyr plugin to configure Module Federation. The first example configuration is using vite-plugin-zephyr directly. The second example is using the official Vite Plugin from Module Federation.
Using the official Vite Plugin from Module Federation.
1. Enable top level await
For vite-plugin-zephyr to work properly with your remotes, you need to set your build target to chrome89 to enable top level await, alternatively you can install vite-plugin-top-level-await plugin to enable it and use it in configuration:
2. Sequence of plugins
Because of how Vite and Rollup are exposing hooks and processing modules in plugins, the sequence of plugins matters where withZephyr() should be after react() but before any other plugins. For example, if svgr() is before withZephyr() it would unexpectedly interrupt the transformed output bundle.
3. Shared dependencies
If the application doesn't show up in the browser, you might be experiencing problems related to dependencies (one of the potential issues), please rememeber to configure modulePreload in your vite.config.ts:
Example project created via npx create-mf-app
Example project created via npx create-mf-app