Micro frontend- and module federiation like architecture #1345
RickStanley
started this conversation in
Other
Replies: 1 comment
-
Thanks for sharing your attempts and thoughs. FYI module federation is on Vite's radar (see Evan You's ViteConf talk). From Vike's side, micro frontend use cases aren't high priority right now, but we're happy to revisit prioritization if we're provided with a strong rationale. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi, I'm trying to set up an architecture similar (or perhaps equal) to that of the title. I was going to classify this discussion as "Help", but this isn't the scope of Vike it seems, and besides, I'm hacking around to see what works and what doesn't.
So I would like to share my attempt(s) and the ideas that I have to achieve what I want, and see if the community have any suggestions.
What I want to achieve
Similar to Module Federation:
But unlike many of the examples that are around (specifically: module-federation-examples), our repository is not unified (aka monorepo) so it gets a bit trickier to set up a configuration that reuses/shares some dependencies.
With that in mind, I'm trying to come up with one in a mixture of: Vite + Preact + Vike, as I didn't want to create my own library that compiles to static assets (HTML) and maintain it. If it is just a plugin that I could use in conjunction with another to complement and achieve my needs, it's enough. Here's what I'm working on: https://github.com/RickStanley/poc-ssg-preact
What I want is:
rollupOptions.exclude
to not bundle libraries, like Preact, together and let the plugin handle theses dependencies. by injecting a import map);index.tsx
(laterdist/client/assets/index.js
) wherein would have the imports and exports of exposable components and routes of that app (much like how it's done with WebPacks plugin Module Federation Plugin, inexposes
properties, but being a file instead;What I got so far
I started by creating a simple plugin: https://github.com/RickStanley/poc-ssg-preact/blob/master/micro.ts.
The problem with shared libraries seems to be easily solvable: copy the library from node_modules, put it in a shared folder and inject importmaps into the static HTML, so it's the shell responsibility to provide the excluded library(ies). It works pretty well, for simple libraries' paths.
I'm having a hard time trying to figure out if
'vike/server'
should be included as shared library, for now, I have this list:And I have to check if Vike's router works out.
Next steps
As I've said, I'll have to check if Vike's router works the way I want, that is: not bundle itself in the page's JS file and if it's configurable through the client (dist/client/), so that I can manipulate at will in the PageShell.
See if it's possible to have some kind of "index.tsx" exist inside pages/ and import and export each pages path to the Blob storage in which it'll reside (this is our specific use case, in this research), so that I can export "myPage.js" and "myPageRemote.js", the later just being a wrapper for dynamic import of the future page's path, injected through environment variable at compile time (Azure Pipelines).
These things seem feasible. Am I missing something, perhaps?
Anyway, I just wanted to share what my goals are and what I'm trying to so far. Any suggestions are welcome!
Beta Was this translation helpful? Give feedback.
All reactions