You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Context:
Let's say I have 2 MFEs - a Host (@corp/host) and an UI lib (@corp/ui) that exposes multiple React components and some of them reuse (or compose) other exposed components.
Let's assume for the example that the UI lib has 2 components - Button and Spinner. They are exposed separately but the Button also import Spinner from '../Spinner';.
Webpack Configurations:
The host has configured the UI lib as a remote:
// Host webpack.config.js - only relevant parts of ModuleFederationPlugin
shared: {
'@corp/ui': '*'
},
remotes: {
@corp/ui: 'ui@http://localhost:3999/remoteEntry.js'
}
The UI lib exposes some components:
// UI lib webpack.config.js - only relevant parts of ModuleFederationPlugin
exposes: {
'./Button': './src/Button',
'./Spinner': './src/Spinner',
}
Issue:
The Host app is consuming the Spinner separately in a parent component but when it loads a @corp/ui/Button, the Spinner code is duplicated in the Button chunk.
Expected result:
I was expecting that the Host will provide the Spinner to Button automatically but it didn't.
Workaround / Question:
The only solution that I found is to:
Add the UI lib to its own shared object with a trailing slash (so that all subpaths are affected too).
Use absolute paths internally. So Button imports Spinner with import Spinner from '@corp/ui/Spinner'; instead of ../Spinner
Final UI Lib config sharing and exposing itself:
// UI lib webpack.config.js - only relevant parts of ModuleFederationPlugin
shared: {
'@corp/ui/': '*'
},
exposes: {
'./Button': './src/Button',
'./Spinner': './src/Spinner',
}
Is this how I'm supposed to do that or I'm missing something?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Context:
Let's say I have 2 MFEs - a Host (
@corp/host
) and an UI lib (@corp/ui
) that exposes multiple React components and some of them reuse (or compose) other exposed components.Let's assume for the example that the UI lib has 2 components -
Button
andSpinner
. They are exposed separately but theButton
alsoimport Spinner from '../Spinner';
.Webpack Configurations:
The host has configured the UI lib as a remote:
The UI lib exposes some components:
Issue:
The Host app is consuming the
Spinner
separately in a parent component but when it loads a@corp/ui/Button
, theSpinner
code is duplicated in theButton
chunk.Expected result:
I was expecting that the Host will provide the
Spinner
toButton
automatically but it didn't.Workaround / Question:
The only solution that I found is to:
shared
object with a trailing slash (so that all subpaths are affected too).Button
imports Spinner withimport Spinner from '@corp/ui/Spinner';
instead of../Spinner
Final UI Lib config sharing and exposing itself:
Beta Was this translation helpful? Give feedback.
All reactions