#
defineBuildRemoteModuleConfig
This is an experimental feature.
Creates an Rsbuild configuration object that is adapted for a Squide remote module application in build mode. This function is a wrapper built on top of @workleap/rsbuild-configs. Make sure to read the defineBuildConfig documentation first.
#
Reference
const rsbuildConfig = defineBuildRemoteModuleConfig(applicationName, options?: {})
#
Parameters
applicationName
: The remote module application name.options
: An optional object literal of options:- Accepts most of Rsbuild
definedDevConfig
predefined options. features
: An optional object literal of feature switches to define additional shared dependencies.i18next
: Whether or not to add@squide/i18next
as a shared dependency.environmentVariables
: Whether or not to add@squide/env-vars
as a shared dependency.honeycomb
: Whether or not to add@squide/firefly-honeycomb
as a shared dependency.msw
:false
to remove@squide/msw
from shared dependencies.
sharedDependencies
: An optional object literal of additional (or updated) module federation shared dependencies.moduleFederationPluginOptions
: An optional object literal of ModuleFederationPlugin options.
- Accepts most of Rsbuild
#
Returns
An Rsbuild configuration object tailored for a Squide remote module application in build mode.
#
Conventions
To fulfill Squide remote module requirements, the defineBuildRemoteModuleConfig
function will pre-configure the ModuleFederationPlugin with the following filename
and exposes
properties.
{
filename: "/remoteEntry.js",
exposes: {
"register.js": "./src/register"
}
}
If the remote module assetsPrefix
is http://localhost/8081
, the remote module bundle is available at http://localhost:8081/remoteEntry.js
.
#
Default shared dependencies
The defineBuildRemoteModuleConfig
function will add the following shared dependencies as singleton
by default:
- react
- react-dom
- react-router-dom
- @squide/core
- @squide/react-router
- @squide/module-federation
- @squide/msw
For the full shared dependencies configuration, have a look at the defineConfig.ts file on Github.
#
Usage
#
Define an Rsbuild config
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1");
#
Activate additional features
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
features: {
i18next: true
}
});
Features must be activated on the host application as well as every remote module.
#
Specify additional shared dependencies
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
sharedDependencies: {
"@sample/shared": {
singleton: true
}
}
});
Additional shared dependencies must be configured on the host application as well as every remote module.
#
Extend a default shared dependency
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
sharedDependencies: {
"react": {
requiredVersion: "18.2.0"
}
}
});
In the previous code sample, the react
shared dependency will be augmented with the newly provided strictVersion
option. The resulting shared dependency will be:
{
"react": {
eager: true,
singleton: true,
requiredVersion: "18.2.0"
}
}
#
Override a default shared dependency
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
sharedDependencies: {
"react": {
singleton: false
}
}
});
In the previous code sample, the react
shared dependency singleton
option will be overrided by the newly provided value. The resulting shared dependency will be:
{
"react": {
eager: true,
singleton: false
}
}
#
Customize module federation configuration
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
moduleFederationPluginOptions: defaultOptions => {
defaultOptions.name = "my-application";
return defaultOptions;
}
});
#
Expose an additional module
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";
export default defineBuildRemoteModuleConfig("remote1", {
moduleFederationPluginOptions: defaultOptions => {
defaultOptions.exposes = {
...(defaultOptions.exposes ?? {}),
"./foo": "./src/bar"
}
return defaultOptions;
}
});