Replies: 7 comments 28 replies
-
I have not used this myself, but as I've been looking for a similar solution I came across this project from Namecheap: http://ilc.namecheap.technology/. If SvelteKit decides to support micro frontends out-of-the-box, then maybe they could borrow some ideas from this project. |
Beta Was this translation helpful? Give feedback.
-
I do not see how you can't already build microfrontends with svelte-kit... what kind of workflow are you looking for? I think this is one of those cases where a technology doesn't advertise itself as something even though it can facilitate that thing... |
Beta Was this translation helpful? Give feedback.
-
Actually already using Svelte as a single among other React single-spas in enterprise. |
Beta Was this translation helpful? Give feedback.
-
I have researched this topic extensively, and I will just say straight up that in my opinion, using Svelte for "MicroFrontends" with Fully Dynamic SSR (Not prerendered), and hydration is insanely wasteful and unneeded. First, of all I will say that using Sveltekit for this is completely out of the option. Sveltekit itself assumes it is in charge of the whole page, and 2 instances can not live together on the same page. This is due to the multiple window globals Sveltekit adds for things like routing. You are also going to run into problems with hydration, since Sveltekit is not going to output clientside hydration scripts in the manner you expect for Microfrontends. So, you are going to need to basically write your own "Sveltekit" meta framework to build Svelte in the way you require for Microfrontends. I know anyone who has done this before will highly recommend that you try to avoid this if you can. Just think about it, Sveltekit is still in beta after over a year with the creator working on it full time, and a ton of other extremely smart people working really hard on it around the clock. The reality is that there is no way you are going to be able to match the quality of Sveltekit, so you need a pretty good argument for not only just not using it but, spending a ton of effort rolling up your own solution. To me, just putting two different separately compiled pieces of html and js together on the page which would most definitely result in performance degradation is not worth it, and I would highly recommend you avoid the misery you would put yourself under to get there. On the technical side, I was actually able to get a quick demo of what you require working. The main problem you are going to run into is the fact that Svelte is not a traditional JS framework, but a compiled language. With this comes several complications over traditional frameworks. Svelte does not have a traditional runtime like other frameworks, components runtimes are compiled at build to save space. Due, to this you have to compile your Svelte twice. Once for the server and once for the hydration on the client, you also have to track these files together which complicates things even further. On top of that, the fact that Svelte "compiles" is going to be a problem. The Svelte compiler does a lot of optimizations, like taking out unused slots, events, etc. which has the boon of saving you a ton on bundle size. This is amazing if you are developing traditionally but, in your case since you are compiling things separately this can cause a ton of problems. The 2 components you are going to have on the page are going to need to be fairly self contained, and probably only communicate through a global store. You also need to avoid a lot of access of global browser window due to having the ability of effecting the other. Again it's possible but, you have to ask yourself is the pain you are putting yourself through worth it? Sveltekit works pretty well right now and is well supported. Svelte's major selling point is how it compiles to decimate bundle size, and you would be throwing all that away, Modern ESM modules and Svelte component already serve as a good supported way to modularize Svelte components. Sveltekit itself also compiles extremely fast, at least in dev, due to Vite so you don't need to worry about build times. I would just recommend to you to save yourself a lot of misery and just stick with Sveltekit and drop Microfrontends entirely. |
Beta Was this translation helpful? Give feedback.
-
i've tried a nice library which seems to play really nice with sveltekit. micro-app. |
Beta Was this translation helpful? Give feedback.
-
Did you find any solution on how to use microFrontend with sveltekit? @vekunz |
Beta Was this translation helpful? Give feedback.
-
MicroFrontends are a relatively new approach, where the concept of splitting a monolithic backend into microservices is brought to the frontend. Today we already split the Frontend into several components at development time, but at compile time these components are merged into one big Frontend. With MicroFrontends parts of the Frontend are outsourced into dedicated web service. The benefit of this is that each MicroFrontend can be developed and deployed independently from the others.
With client-side rendering, the browser can now fetch the JavaScript and CSS files for each MicroFrontend individually from each web service. But I think we all know the benefits of server-side rendering. Currently, there are several small libraries for MicroFrontends with server-side rendering, but they are not compatible with Frameworks like Angular, Next.js, Nuxt.js, or SvelteKit.
I think it would be a great benefit if SvelteKit supports MicroFrontends with server-side rendering out of the box.
If you still do not have any clue what MicroFrontends should be, there is a good website that explains the topic very good https://micro-frontends.org/.
Beta Was this translation helpful? Give feedback.
All reactions