If you have an Nx workspace setup for Micro-Frontend application in place with Webpack and curious about how to migrate to Rspack and use Zephyr - this documentation is for you.
If you don't have nvm
to manage your node version yet, head to the official nvm guide to install it.
An example contains line-by-line changes in our example repository.
Within your project directory, run below commands to install required packages for rspack
and Zephyr's npm package:
module-federation.config.ts
Every module-federation.config.ts
's import needs to be replaced by
webpack.config.ts
and webpack.config.prod.ts
Rename webpack.config.ts
to rspack.config.ts
and change all import path to below. While changing the import path, we will also add Zephyr's plugin to build configuration.
Rename all webpack.config.prod.ts
to rspack.config.prod.ts
and within the file (of each remotes), change the import path:
For Host application's rspack.config.prod.ts
, you will need to do the same changes as rspack.config.ts
:
In every project.json
, you will need to edit below changes:
@nx/rspack:rspack
2. Add "target":"web"
to build options (this inferred a )build
's options
-- change all "webpackConfig":"apps/{appName}/webpack.config.ts"
to "rspackConfig": "apps/{appName}/rspack.config.ts"
configurations
's production
config -- change all "webpackConfig":"apps/{appName}/webpack.config.prod.ts"
to "rspackConfig": "apps/{appName}/rspack.config.prod.ts"
executor
in serve
-- change @nx/react:module-federation-dev-server
to "@nx/rspack:module-federation-dev-server"
In each of the applications, hosts or remotes, it will need a package.json
file with name
and version
field in order for Zephyr to map the remote's name.
If you are naming host
application in Module Federation configuration like:
You will need a package.json
like so within the host
's folder:
Before we deploy to Zephyr, make sure:
git
repositoryremote.origin.url
Since this is a Micro-Frontend application, you will need to build the remote first by running each of these command in sequence. Remotes must be built first for Zephyr to map them in host applications. Read more.
First:
Second:
Third: