Vite is the first build tool Zephyr is able to handle Module Federation configuration directly. 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.
If you don't have nvm
to manage your node version yet, head to the official nvm guide to install it.
For applications built with Vite:
For applications built with Webpack and Rspack:
Four example build configuration for Vite, Rspack and Webpack.
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