Closed
Description
Version
System:
OS: macOS 13.2.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 967.52 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Browsers:
Chrome: 133.0.6943.98
Safari: 16.3
npmPackages:
@rslib/core: * => 0.5.0
Details
I'm experimenting with rslib to achieve that:
- Create a lib package as module federation consumer
- Import the package to another app
Therefore, based on the official rslib example, I created the following structure:
- A package,
dep
, contains a timestamp when the package is initially loaded mf-remote
, a mf provider that depends ondep
mf-react-component
, a mf consumer. It loadsmf-remote
dynamically and it also imports fromdep
. I expectdep
to be shared, which means it should only load once and timestamp should be the same. I also expectmf-react-component
could be built as a lib.mf-host
, an app that imports frommf-react-component
Now I am not sure how to configure rslib.config.ts
, I tried the following:
export default defineConfig({
lib: [
{
format: "esm",
// ...
},
{
format: "cjs",
// ...
},
],
// ...
plugins: [
pluginModuleFederation({
name: "rslib_provider",
exposes: {
".": "./src/index.tsx",
},
shared: {
react: {
singleton: true,
},
"react-dom": {
singleton: true,
},
dep: {
singleton: true,
},
},
}),
],
});
However, it seems the output still imports/requires from dep
instead of special module federation treatment.
My question is:
- Should the scenario (build a MF consumer as a lib) be supported?
- If so, is it currently supported? How to adjust the configuration?
Reproduce link
https://github.com/yf-yang/rslib-experiments
Reproduce Steps
pnpm i
pnpm build:lib
pnpm dev:all:host
Check logs
timestamp from host
and timestamp from remote
are different
Metadata
Assignees
Labels
No labels
Activity