import {getRsBuildConfig} from "rsbuild-config/rsbuid-core";- config: type RsbuildConfig
- opts: type IProps
interface IProps {
enableCopy?: boolean;
moduleFederation?: ModuleFederationPluginOptions;
}export default defineConfig(
getRsBuildConfig(
{
server: {
port: 3001
}
},
{
moduleFederation: {
dts: false,
manifest: false,
name: "appStore",
exposes: {
"./store": "./src/store/index.ts"
},
filename: "remoteEntry.js"
}
}
)
);- config same module federation v2.0
export default defineConfig(
getRsBuildConfig(
{
server: {
port: 3000
}
},
{
moduleFederation: {
dts: false,
manifest: false,
name: "host"
}
}
)
);- For each app there will be a file named
remote.jsonlocated in the root directory. It will be a json array, will be the name of the apps in theappsfolder - Ex: The host app needs two remote apps named
remoteandstore. In the folderapps/host/remote.jsonthere will be the following values:
[
"store",
"remote"
]
- Same with
apps/remote/remote.jsononly remote namedstore.
[
"store"
]- Also in the
public/assets/config.jsonfolder, this is where you will add all the remote paths:
[
{
"name": "remote",
"alias": "remote",
"entry": "http://localhost:3002/remoteEntry.js"
},
{
"name": "appStore",
"alias": "appStore",
"entry": "http://localhost:3001/remoteEntry.js"
},
...
]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");pnpm run ${action} ${name}
- action:
dev,build,preview,lint... - name: name app
- With host
pnpm run dev host
- You can also do the same with
build,preview,doctor,lint