Home

Awesome

Config rsbuild

config base

import {getRsBuildConfig} from "rsbuild-config/rsbuid-core";

interface IProps {
    enableCopy?: boolean;
    moduleFederation?: ModuleFederationPluginOptions;
}

with remote app

export default defineConfig(
    getRsBuildConfig(
        {
            server: {
                port: 3001
            }
        },
        {
            moduleFederation: {
                dts: false,
                manifest: false,
                name: "appStore",
                exposes: {
                    "./store": "./src/store/index.ts"
                },
                filename: "remoteEntry.js"
            }
        }
    )
);

with host app

export default defineConfig(
    getRsBuildConfig(
        {
            server: {
                port: 3000
            }
        },
        {
            moduleFederation: {
                dts: false,
                manifest: false,
                name: "host"
            }
        }
    )
);

File

[
  "store",
  "remote"
]

[
  "store"
]
[
  {
    "name": "remote",
    "alias": "remote",
    "entry": "http://localhost:3002/remoteEntry.js"
  },
  {
    "name": "appStore",
    "alias": "appStore",
    "entry": "http://localhost:3001/remoteEntry.js"
  },
  ...
]

Usage

const AppRemote = loadable(
    () => loadRemote<typeof import("remote/App")>("remote/App"),
    {
        fallback: <p>Loading...</p>,
        resolveComponent: (m) => m.default
    }
);

const {useBearStore} =
    await CustomLoadRemote<typeof import("appStore/store")>("appStore/store");

Run

pnpm run ${action} ${name}

With project you can run:

pnpm run dev host