Replies: 2 comments
-
uh... the Svelte demo is now 404. Does it mean Vite + Svelte is not supported? |
Beta Was this translation helpful? Give feedback.
-
Update: if I only add the scope of the package ( const {
withNativeFederation,
shareAll
} = require('@softarc/native-federation/build');
module.exports = withNativeFederation({
name: 'remote',
exposes: {
'./remote-app': './src/App.svelte'
},
shared: {
...shareAll({
singleton: true,
strictVersion: true,
requiredVersion: 'auto',
includeSecondaries: false,
}),
'@scope': {
singleton: true,
strictVersion: true,
requiredVersion: 'auto',
includeSecondaries: false,
}
},
}); Somehow the remote app can build and run, with just one tiny warning:
I think I know what does it mean. But I don't know how to fix it. I don't even know who is complaining about it. Is it Vite? The Federation-Vite plugin? Or the EsBuild-Svelte plugin? And when I run both the host and remote apps, it seems the shared component is loaded at least twice. Not sure if it is the correct behaviour. But at least it runs. Still looking for a better answer. |
Beta Was this translation helpful? Give feedback.
-
I'm pretty new to module federation. I have checked the example vite-svelte-microfrontends and successfully recreated a working app on my end. But when I try to integrate my Svelte component library, it either fails to build or fails to run. So, what is the correct way to configure module federation to support shared component library?
Think of the
rxjs
dependency in the example, but is a Svelte component library instead. And itspackage.json
looks like this:And I want both host and remote uses the same
<Counter/>
component from the library. Host builds and runs fine. But Remote refuses to cooperate. Most likely my fault.If I don't change anything in
federation.config.cjs
,vite build
fails with the following messages:Seeing the last line of the message, I tried adding
@scope/counter
tobuild.rollupOptions.external
ofvite.config.js
. Same error.I have tried adding it in the
skip
property offederation.config.cjs
. Same error.I have tried adding it in the
shared
property offederation.config.cjs
. Nowvite build
output some files, but with error messages:Sadly,
vite dev
still fails.Any help would be appreciated. 🙏
Edit: I have created a minimal project to illustrate the problem.
https://github.com/Mooncat25/module-federation-svelte
Beta Was this translation helpful? Give feedback.
All reactions