micro-frontend | 微前端框架 之 single-spa 从入门到精通 | Single Page Application library
kandi X-RAY | micro-frontend Summary
kandi X-RAY | micro-frontend Summary
微前端框架 之 single-spa 从入门到精通
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- React to route changes
- Rebuild the parcel .
- Load an app app .
- Perform single app changes
- Validates a config object
- Main mount method .
- Build a production build
- Resolve time .
- Registers an app
- Unload an app
micro-frontend Key Features
micro-frontend Examples and Code Snippets
Community Discussions
Trending Discussions on micro-frontend
QUESTION
I chanced on Piral Framework for implementing micro-frontends and I wanted to implement it in my project.
However, my application comes as a Blazor wasm project and my aim is to use this current project as my app shell.
Is there any example on how I could implement that?
I can't really find my way around the documentation too.
Kindly note that I am a beginner. Thanks in advance.
...ANSWER
Answered 2022-Jan-21 at 11:06For the app shell you cannot use Blazor.WASM. You can, however, make your app shell really lightweight (i.e., don't put almost anything in there) and have all the necessary layout parts defined in Blazor.
The idea boils down to the sample given at: https://github.com/piral-samples/piral-distributed-layout
Now instead of having pilet(s) in React / Angular / ... you use Blazor.
For Blazor pilets (and extensions using Blazor) you can check out the documentation at the README of Piral.Blazor: https://github.com/smapiot/Piral.Blazor/
Make sure to follow the instructions closely and use the right branch (named after the version of Blazor you are targeting).
QUESTION
I'm building an app with micro-frontends using webpack 5's module federation plugin. Everything was fine until I started adding react hooks into my remote app. At that point I received errors about "invalid usage of hooks", i.e. I discovered I had TWO versions of react loaded, one from the remote and one from the app consuming the remote.
That problem was solved by adding a shared
key to the ModuleFederationPlugin
section of my webpack config that marked React as a singleton. Now everything compiles and seems to run just fine.
However, the webpack compiler is throwing some annoying warnings at me now. Its saying:
...ANSWER
Answered 2022-Feb-25 at 13:38Fixed my own problem by changing the key version
to requiredVersion
QUESTION
I've been creating a micro-frontend project and the glue (nginx) isn't working as expected.
My projects are structured as such:
...ANSWER
Answered 2021-Dec-08 at 21:09The primary issue is that localhost:
is not accessible between containers. The containers should reference the service names defined in docker-compose.
nginx.conf
becomes:
QUESTION
Given the growing size of frontend code, the concept of micro-frontend and module federation provided by Webpack 5 is a possible solution. However, considering the possibility that you are integrating code from other teams / 3rd parties, the foreign code could potentially try to access information it's not meant to by simply accessing the window
object and iterating through its children.
This doesn't have to be critical information like passwords and credit cards, which are often isolated using an iframe
. Less sensitive information like user emails, or tracking data could be collected and misused.
In this case, is there any technical set up that doesn't involve iframes
that could limit the access scope of scripts? Is this something that could technically be implemented inside a WebAssembly program?
Edit: Yes, the conservative rule is to simply not run untrusted code. The question posed however is if it's technically possible to sandbox frontend code without using iframe
to limit its access to information.
ANSWER
Answered 2021-Oct-26 at 03:17Javascript is inherently "public", so at some point stuff you put in or get out will eventually be exposed, either through the network fetch/XHR, or through function execution.
There is a "private" pattern in javascript, which prevents snooping around inside an object -- where you explicitely define the methods/properties that are exposed:
QUESTION
I'm using Angular with Webpack 5 Module Federation for micro-frontends. I have 2 apps (let's call them app1 and app2) and my main app, app1, is federating components of app2.
In app2, my exposed components are exported by my main module, so when I try to federate some component, I can get it from the export section of my module. Everything works fine in dev mode, I can get my exposed module, retrieve my exported components and then use the component factory resolver to create it where I want in app1.
But when I build in production (I used ng serve --prod to reproduce the prod environment and test it) my exported components are gone but not the imports and providers. This is the module I get:
...ANSWER
Answered 2021-Oct-18 at 14:51Fixed it by using a static field in my module as suggested here.
QUESTION
I am trying to build a simple micro-frontend example using Vue3 and Module Federation but I have a collision problem.
I have the code here: https://github.com/ghalex/mf-example
There are only two mf:
- container (Vue3)
- auth (Vue3)
The problem I have is that when I import the App.vue component:
...ANSWER
Answered 2021-Aug-31 at 15:12I found the problem, it is a webpack-dev-server
v4 bug. I downgraded to v3 and everything works fine.
QUESTION
I'm trying to write unit tests for a react spa web application that uses micro-frontend architecture. My first step is to write unit tests for the application container.
The application container react component uses a react-router containing a switch with subsequent routes to render the components in the main content area.
Each application is mounted to the application container using JavaScript runtime integration.
I'm using React-Testing-Library and Jest as part of my testing toolset.
I've searched high and low across the Internet and haven't found any useful articles on the issues I'm having. Most of them show a demo of testing a web application that doesn't relate to my scenario.
I have 3 problems that I would like some guidance on.
Since Micro Frontends are composed of multiple layers of components chained together with authentication and other business logic. Should I be testing the "page components" only? Or should I be testing the entire application container starting from the App component? If neither is true, how should I be testing this application?
I tried to test on the page component level to avoid authentication issues and for simplicity sake, but the component contains a component from React Router library, and Jest is complaining that I should not be using
component that isn't enclosed within a
component. However, the
component is present at the parent component level when executed in runtime. How can I tell Jest to "ignore" this problem?
I could not find a configuration that allows me to ignore this error.
Due to issue #2, I tried to write unit tests by rendering the
component, but this component is passed into a Higher Order Component that performs authentication validation. How can I focus on testing the end result instead of the functionality of the authentication HOC just so I can get the component to render and for my tests to execute?
ANSWER
Answered 2021-Aug-09 at 01:39In general, you should test each component and you should make assertions only about the logic contained within that component.
For instance, let's pretend your App component looks like this:
QUESTION
The question:
How (is it possible) to configure webpack (with single-spa), to take make some packages (projects) under a scope (@orginazation) externals and other internals (not external) ?
Project information:
We are building a single-spa application using webpack an uses Github npm registrer (and github actions). All the micro front-ends are projects in Github, and some of them are util/helper/provider projects, that is compiled as externals with webpack.
But some of them are meant to be compiled with the micro-frontend (must not be external)
It seems that when webpack sees one of the project under the organization scope as external, it set all package under that scope to external!
As we can see from the log the "CompilingTool" will also be compiled as external, event thought it should not.
The packages are set in the files as:
...ANSWER
Answered 2021-Aug-05 at 15:14This is possible by passing in orgPackagesAsExternal: false
to the single-spa webpack config, in your case named singleSpaDefaults
. Per the create-single-spa documentation,
This changes whether package names that start with @your-org-name are treated as webpack externals or not. Defaults to true.
You will then need to either:
- Enumerate which packages to mark as external
- Provide a function that does this (which you've noted in your question)
and then merge that with single-spa's config as usual. Because this can become verbose and annoying to do for every microfrontend, consider doing this in a base config that you publish that is specific for your company and which each mfe will then need to consume.
QUESTION
Imagine you are developing a big-scale nuxt app that has 100 routes. what is the best solution for managing routes (not micro-frontend) in this app?
...ANSWER
Answered 2021-Jul-27 at 15:47What do you mean by this?
or should add all of them in pages directory?`
Here, we're talking about pages only, right? So /user/id
, /post/id
and so on?
If it's the case, you could have a /_entity/id
or even a /_entity/_slug
for more flexibility (with _entity
being either user
or post
etc...).
If you have a lot of various pages like /about
, /our-team
, /careers
and so on, I guess that those will need their own SEO, content and are totally legit.
I don't really see why this would be an issue at all. It will be properly organized, scalable and will not have too much abstraction neither (which is important IMO).
You could also export some of those pages into .md
files thanks to nuxt/content
and import them into the pages. Like the Nuxt documentation is doing.
If you really need to simplify those, yeah you could make the whole templates dynamic and generate the markup on fly. This could introduce some huge complexity that may not be needed IMO.
Also, layouts, slots and render functions can be a solution too I guess.
I'm not sure if micro-frontends (sounds like a buzz word for me) are actually several instances on Nuxt one next to another (sounds like a terrible idea if hosted under the same domain) or just "component-ization" of your non monolithic fullstack app (pretty much how we build websites for few years already).
But for me, if a project do have 100 pages
, it is totally fine.
Of course, having some hardcoded /blog/post/1
, /blog/post/2
is bad (lol) but a large app could be totally fine. It may create some issues regarding the build time and so on, but this is another subject and relies more of the way you do generate the project.
So yeah, if your interviewer wanted to go deeper than those approaches, you would need more details from him to exactly know what are the challenges and what could be used.
TLDR: as far as I know, no frameworks aim to reduce the number of pages because this is not an issue by itself. 10k Nuxt pages will not make your /about
one slower by any means (if it does, the issue is elsewhere).
QUESTION
The stack is way too complicated to recreate it, so forgive me in advance and ask me for further information.
The Angular app has the following structure:
...ANSWER
Answered 2021-Jun-03 at 22:14The issue was the way I did the bootstrap for the Angular application
Wrong approach:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install micro-frontend
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page