# defineBuildHostConfig

Creates an Rsbuild configuration object that is adapted for a Squide host 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 = defineBuildHostConfig(remotes: [], options?: {})

# Parameters

  • remotes: An array of RemoteDefinition (view the Remote definition section).
  • options: An optional object literal of options:
    • Accepts most of Rsbuild definedBuildConfig 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.
    • runtimePlugins: An optional array of module federation runtime plugins.
    • sharedDependencies: An optional object literal of additional (or updated) module federation shared dependencies.
    • moduleFederationPluginOptions: An optional object literal of ModuleFederationPlugin options.

# Returns

An Rsbuild configuration object tailored for a Squide host application in build mode.

# Default shared dependencies

The defineBuildHostConfig function will add the following shared dependencies as singleton by default:

For the full shared dependencies configuration, have a look at the defineConfig.ts file on GitHub.

# Usage

# Define an Rsbuild config

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes);

# Activate additional features

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes, {
    features: {
        i18next: true
    }
});

# Specify additional shared dependencies

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes, {
    sharedDependencies: {
        "@sample/shared": {
            singleton: true
        }
    }
});

# Extend a default shared dependency

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes, {
    sharedDependencies: {
        "react": {
            requiredVersion: "18.2.0"
        }
    }
});

In the previous code sample, the react shared dependency will be augmented with the strictVersion option. The resulting shared dependency will be:

{
    "react": {
        eager: true,
        singleton: true,
        requiredVersion: "18.2.0"
    }
}

# Override a default shared dependency

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes, {
    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

host/rsbuild.build.ts
import { defineBuildHostConfig, type RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];

export default defineBuildHostConfig(Remotes, {
    moduleFederationPluginOptions: defaultOptions => {
        defaultOptions.name = "my-application";

        return defaultOptions;
    }
});

# Remote definition

# name

The name option of a remote definition must match the name option defined in the remote module ModuleFederationPlugin configuration.

If you are relying on the Squide defineBuildRemoteModuleConfig function to add the ModuleFederationPlugin to the remote module Rsbuild configuration object, then the remote module name is the first argument of the function.

In the following exemple, the remote module name is remote1.

host/rsbuild.build.ts
import type { RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: `http://localhost:8081` }
];
remote-module/rsbuild.build.ts
import { defineBuildRemoteModuleConfig } from "@squide/firefly-rsbuild-configs";

export default defineBuildRemoteModuleConfig("remote1");

# url

The url option of a remote definition must match the assetPrefix of the remote module Rsbuild configuration object.

In the following exemple, the remote module assetPrefix is http://localhost:8081.

host/rsbuild.build.ts
import type { RemoteDefinition } from "@squide/firefly-rsbuild-configs";

const Remotes: RemoteDefinition[] = [
    { name: "remote1", url: "http://localhost:8081" }
];