<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ilya Isupov on Medium]]></title>
        <description><![CDATA[Stories by Ilya Isupov on Medium]]></description>
        <link>https://medium.com/@i.s.isupov?source=rss-df9702fe676d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*awHmVZJZ4DVznosVaAWIHg.png</url>
            <title>Stories by Ilya Isupov on Medium</title>
            <link>https://medium.com/@i.s.isupov?source=rss-df9702fe676d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:08:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@i.s.isupov/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Webpack Module Federation: Micro-Frontend Powered by Modern Technologies (Part 2) — Deep Dive]]></title>
            <link>https://medium.com/netcracker/webpack-module-federation-micro-frontend-powered-by-modern-technologies-part-2-deep-dive-d10b3fbe3c3e?source=rss-df9702fe676d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d10b3fbe3c3e</guid>
            <dc:creator><![CDATA[Ilya Isupov]]></dc:creator>
            <pubDate>Wed, 15 Dec 2021 14:50:59 GMT</pubDate>
            <atom:updated>2021-12-15T14:53:50.216Z</atom:updated>
            <content:encoded><![CDATA[<h3>Webpack Module Federation: Micro-Frontend Powered by Modern Technologies (Part 2) — Deep Dive</h3><p>Based on the questions from the <a href="https://medium.com/netcracker/webpack-module-federation-micro-frontend-powered-by-modern-technologies-8bd426e996da">previous article</a>, we decided to write Part 2 and tell you what else we have successfully accomplished.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/0*PcDzwip8avCK_Khw.jpg" /></figure><p>Agenda:</p><ul><li>Host application routing (React/Vue Routing inside Angular)</li><li>Fully-featured adapters for remote plugins</li><li>Using service modules at runtime</li></ul><p><strong>Routing</strong></p><p>In the first part of the <a href="https://habr.com/ru/company/netcracker/blog/568054/">article</a>, we created a <a href="https://github.com/ilya-isupov/multi-framework-module-federation">pet project</a>, in which we used an Angular host and remote Angular plugins. In such a combination, the routing of the host application covers all options for the native use of the application. For example, there is the <strong>/plugin</strong> route in the host application, and the plugin contains two routers:<strong> /first </strong>and <strong>/second</strong>. As a result, we will get <strong>/plugin/first</strong> and <strong>/plugin/second</strong> in the finished application. Such a system will work perfectly at any nesting level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*sZwMtBLkRxYmfZJkEt9pjg.png" /></figure><p>Let’s consider an example of a child routing for an Angular plugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*Q-Pkxh0x5PhWYQIIO7Bc2g.png" /></figure><p>Consider the following task: in an Angular application, use a plugin written in a different framework — React.</p><p>This usually poses the question: why are you doing this? And why not write everything in one framework? Let’s digress from techniques and explain.</p><p>Indeed, it is worth doing on projects of simple and medium complexity, if it is possible to use the same technologies by all teams. The task to combine several frameworks is relevant for complex projects, where independent teams from different domains (microservices) develop their components, in their release cycles, using different technologies. Further, these components should be used in the same interface. Our experience shows that the world becomes more complicated, therefore, IT systems become more complicated as well, and such complex projects grow in number.</p><p>As an example, let’s take the workplace of a contact center agent. On this screen, we see the financial information developed by the Billing team that is highly reliable and rarely changes. And here is a widget with the trendy Next Best Action, written by a dynamic team of hipsters who are constantly experimenting. There are also chatbots, scripting, marketing promotions, wizards for solving technical problems, knowledge bases, and much more. Under each component, there is a large amount of business logic as well as large teams developing it.</p><p>You must admit that it is wrong to impose using certain technologies on a team as it would contradict the idea of microservice architecture.</p><p><strong>Let’s go back to techniques.</strong></p><p>If we simply create an Angular route <strong>/react</strong> in our host application and inject the React plugin with routing under it, then everything will work, but not exactly as expected.</p><p>Create routing in the React plugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*8dvAnLO79hPePA1cedPbEQ.png" /></figure><p>In this implementation, when switching to <strong>/react</strong>, we will see that the URL in the browser changes to <strong>&lt;host_url&gt;/first</strong>. This is not what we expect. Solve the problem using <a href="https://reactrouter.com/web/api/BrowserRouter">basename</a>. Idea: we need to forward the route from the host application, under which the React plugin is stored, to the plugin itself in order to initialize the BrowserRouter with the correct basename. In a few words, the basename is the URL against which the React routing will be built.</p><p>Thus, forward it on the host side. Obviously, we need the <strong>routePath</strong> value directly from the plugin configuration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*rt0Dhsrdh7S6Gr82k2gFQQ.png" /></figure><p>Accept it on the plugin side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*KGWhnfsAJ3izgMpfn8GL2w.png" /></figure><p>We get a ready full-featured solution <strong>Angular Router + React Browser Router</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*oONC7C9DG1lCK7h6oSL6yg.png" /></figure><p><strong>Super Native Adapters for Micro-Frontend</strong></p><p>Let’s consider:</p><ul><li>Angular Adapter</li><li>React Adapter</li><li>Vue Adapter</li></ul><p>Initializing some plugin with a set of props (properties) is easy, but this solves only half the problem. What if we want to use a remote plugin as part of our application, as a dumb component, just as a component that sometimes needs props from the host or another plugin?</p><p>Create a Change Detector for our plugins. We already have a detector. Now let’s learn to pass props to plugins:)</p><p>The props scheme should be clear to everyone, but just in case, let’s draw a picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*c_y-qf-yzde7zXwWYpfQaQ.png" /></figure><p><strong>Assumption</strong>. On the plugin side, you can get the updated props only in the setter, because we are routing them manually, and not by the standard change detection cycle.</p><p><strong>Angular Adapter</strong></p><p><strong>Components</strong></p><p>We have slightly updated/rewritten our Angular adapter, and we have ended up with the <a href="https://github.com/ilya-isupov/multi-framework-module-federation/blob/master/angular-shell/src/app/components/angular-wrapper/angular-wrapper.component.ts">following code</a>.</p><p>The new features include the option to use any component from any module from any remote repository with the necessary providers. This means that if we have a module in the plugin repository with a component that uses a service, which provides the same module, we can export the entire module with its service providers without worrying that some service gets lost.</p><p>How to implement it:</p><p>On the plugin side, we should provide the module and component we want to use. One module is not sufficient, because all component factory of this module will not get into the bundle (tree-shakable components) at build -prod, and there remains one module with the injector.</p><p>It looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*KAW2rXNQtttg9ufoTJtjYw.png" /></figure><p>On the side that receives the plugin, there must be an advanced configuration, like the following one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/970/1*CYoZC-n1wg5tm5Mps-mKuQ.png" /></figure><p>These four properties framed in red ensure that the module and plugin components can be loaded.</p><p>We can load the plugin in the following way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*PqRb0xlepkDgs05CAIb6FQ.png" /></figure><p>Here is the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*sHv6XRWB9ZZW61yo8hnyfA.png" /></figure><p>This code gives us free rein! Now we can retrieve any component from any module :)</p><p><strong>And what about services? We also can!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/313/1*pBHZgmrODq1nLJ0v__BG6g.png" /></figure><p>Why use shared services from remote modules? We have a set of backend services that provide us with a REST API. Each service supports a specific business. When two plugins need to access the same backend, each plugin must create a GraphQL query, add a GraphQL module implementation to the repository, and remember about the data models. (╯°□°）╯︵ ┻━┻.</p><p>The idea is to create master UI services for backends. Then each backend has one Singleton service for the entire application (for the host and all plugins). We will use them at runtime.</p><p>Let’s provide the service in the remote module like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*3PWnZxnjY2biigmkI3qKeQ.png" /></figure><p>This is necessary so that to retrieve it from the injector using the following string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*Zrgh7TPeDBo1XI4XCOUqMg.png" /></figure><p>Let’s be honest: the way we can use this service is not ideal, but at least now we can do it. Everything is so complicated because we’re pulling out of the injector not the service only, but the service with all of its dependencies, if any. And there is no need to provide anything additionally on the consumer side — <strong>everything will automatically start working</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/1*wF8iuLgKyFSOK34XWF9SJA.png" /></figure><p><strong>React Adapter</strong></p><p>The Angular-React adapter will be a bit simpler. Since it is much easier to expose from React as there is no need to divide components into smart and dumb, we will not include this in the adapter implementation either.</p><p>We should be able to:</p><ul><li>Render a component under the route;</li><li>Render a component anywhere in the Angular component using the adapter.</li></ul><p>Under the route, we already know how to implement the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*zFTZuh7n1ANpolG92B6HHQ.png" /></figure><p>And now let’s learn how to render a component at a randomly selected point. Conceptually, it will be the same as for the Angular plugin. You should simply insert the React adapter for the plugin into the template, and then add the plugin configuration and props to the template.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*fYBtuEpYU1tP5uQOKmzuAQ.png" /></figure><p>The adapter renders the plugin:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*7Xp7wn5jngbtzlxuJTG1qw.png" /></figure><p>And installs the props upon receiving them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*zA8RCubHmVUub2b9o8bwaw.png" /></figure><p>Remember to execute unmount after the component is destroyed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*xYeM_2upg3GJStR-hpgCZw.png" /></figure><p>Success :)</p><p><strong>Vue Adapter</strong></p><p>The adapter code for Vue is structurally the same as for the React and Angular adapters. The main difference is only in the code of the renderer, component, or application itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*n4xdfVbRLk6lraxqu6rFTA.png" /></figure><p>We get the component and, accordingly, “mount” it on the adapter host element.</p><p>We can also write a self-invoking adapter, which can be used in the case when the logic of binding settings, routing configuration, and libraries connection is assigned to a remote plugin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*xb9DBxF6HVo84gfGomjtuA.png" /></figure><p>And already in the Vue project, export the bootstrap function, for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*6a4ipA3gbVKijdDdjFt6FQ.png" /></figure><p>in which we simply use the forwarded element and attach the component (the application) to it.</p><p>Since Module Federation allows exposing any javascript, the Webpack configuration will not change much.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*Lz3BNVFllqggTsXXTSIJrw.png" /></figure><p>All the code discussed can be found on <a href="https://github.com/ilya-isupov/multi-framework-module-federation">github</a>.</p><p>P.S. Thanks Anton (telegram: @poetique) and <a href="https://medium.com/u/91eff8644401">Ivan</a> for help in implementing Vue adapter and React child routing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d10b3fbe3c3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/netcracker/webpack-module-federation-micro-frontend-powered-by-modern-technologies-part-2-deep-dive-d10b3fbe3c3e">Webpack Module Federation: Micro-Frontend Powered by Modern Technologies (Part 2) — Deep Dive</a> was originally published in <a href="https://medium.com/netcracker">netcracker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack Module Federation: Micro-Frontend Powered by Modern Technologies]]></title>
            <link>https://medium.com/netcracker/webpack-module-federation-micro-frontend-powered-by-modern-technologies-8bd426e996da?source=rss-df9702fe676d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bd426e996da</guid>
            <dc:creator><![CDATA[Ilya Isupov]]></dc:creator>
            <pubDate>Thu, 09 Dec 2021 15:37:31 GMT</pubDate>
            <atom:updated>2021-12-15T09:42:26.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LovUsIkvC6R_SDiMrpBRdg.jpeg" /></figure><p>Hi Medium! At Netcracker, we’ve been using a micro-frontend architecture for a long time, and since 2017 we’ve started developing our own platform tool for building micro-frontends.</p><p>Recently in the scope of a <a href="https://youtu.be/SuhLqIVolWU">meetup</a>, we have shown how to create complex applications developed by different teams in different release cycles and even technologies. In the live coding mode, we have combined Angular, React, and Vue into one SPA. There have been a lot of questions about the Webpack Module Federation. Since we are already migrating to this framework, here we will share our experience on how to create Angular host application + React/Angular/Vue micro-frontends with the option of independent versioning of the dependencies.</p><h3>Goals</h3><p>So the task is to build a working prototype according to all the rules of the microservice world in the frontend. This means that our prototype must have:</p><p>1. No coupling between plugins;</p><p>2. A common event bus for communication between plugins;</p><p>3. True-routing in host application;</p><p>4. Maximum re-use of repetitive “dumb” components.</p><p>It seems easy, but there are some interesting nuances. First of all, we should ensure the unlimited choice of frameworks and their versions. Secondly, there should be an option to add a dependency on any necessary library for each component. Thirdly, we should have a solution for how to arrange all of this into one big application with the sharing option as well as with maximum components re-use.</p><h3>Minimum Requirements</h3><p>For a high-level description of the future prototype, we have defined the following requirements:</p><p>1. Each service must be implemented in a separate repository and have its own CI/CD;</p><p>2. At the build stage, no one should know about the future neighbors. In this case, we are referring, of course, to the technical settings of the builder;</p><p>3. Plugins must be loaded dynamically, at runtime;</p><p>4. The plugins location should be dynamically selected;</p><p>5. There should be no customization of the current open-source solutions;</p><p>6. We should develop only a conceptual idea, a prototype, but without any complicated frameworks;</p><p>7. The host application should be able to embed plugins written in different frameworks, without restrictions by dependencies and their versions;</p><p>8. The prototype must dynamically configure a set of plugins in the application;</p><p>9. Each plugin should be able to use any library, regardless of what libraries are available in the host application.</p><p>This was the set of requirements we started our development with. But there is much of coding ahead!</p><h3>Host Prototype</h3><p>Our eager readers who like visual content, take a look at the <a href="https://github.com/ilya-isupov/multi-framework-module-federation">repository</a>:) But you’d better stay with us and watch all the steps!</p><p>The steps for migrating to the Module Federation concept do not vary much for different applications. The only difference will be the set of shared packages and modules, which we post for future use.</p><p>Below you can find step-by-step instructions and an example of how to migrate an existing Angular application. We use it to create a host that will aggregate plugins by routes.</p><p>In package.json, add the option to resolve dependencies using Webpack 5:</p><pre>&quot;resolutions&quot;: {&quot;webpack&quot;: &quot;^5.0.0&quot;}</pre><p>Set Yarn as the default package manager:</p><pre>ng config cli.packageManager yarn</pre><p>Add the package <a href="https://habr.com/users/angular-architects/module-federation:">@angular-architects/module-federation</a> to the project:</p><pre>yarn add @angular-architects/module-federation</pre><p>Configure the host application so that it can share its dependencies. At this stage, we use the default scope only.</p><pre>// webpack.config.js</pre><pre>const webpack = <em>require</em>(&quot;webpack&quot;);<br>const ModuleFederationPlugin = <em>require</em>(&quot;webpack/lib/container/ModuleFederationPlugin&quot;);<br>const mf = <em>require</em>(&quot;@angular-architects/module-federation/webpack&quot;);<br>const path = <em>require</em>(&quot;path&quot;);<br>const dependencies = <em>require</em>(&quot;./package.json&quot;).dependencies;<br><br>const sharedMappings = new mf.SharedMappings();<br>sharedMappings.register(<br>  path.<em>join</em>(__dirname, &#39;tsconfig.json&#39;),<br>  [<em>/* mapped paths to share */</em>]);<br><br>module.exports = {<br>  output: {<br>    uniqueName: &quot;angularShell&quot;,<br>    publicPath: &quot;auto&quot;<br>  },<br>  optimization: {<br>    runtimeChunk: false<br>  },<br>  resolve: {<br>    alias: {<br>      ...sharedMappings.getAliases(),<br>    }<br>  },<br>  plugins: [<br>    new webpack.ProvidePlugin({<br>      &quot;React&quot;: &quot;react&quot;,<br>    }),<br>    new ModuleFederationPlugin({<br>      shared: {<br>        &#39;@angular/common/http&#39;: {<br>          requiredVersion: dependencies[&#39;@angular/common&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/common&#39;: {<br>          version: dependencies[&#39;@angular/common&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/core&#39;: {<br>          version: dependencies[&#39;@angular/core&#39;],<br>          requiredVersion: dependencies[&#39;@angular/core&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/platform-browser&#39;: {<br>          version: dependencies[&#39;@angular/platform-browser&#39;],<br>          requiredVersion: dependencies[&#39;@angular/platform-browser&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/platform-browser-dynamic&#39;: {<br>          version: dependencies[&#39;@angular/platform-browser-dynamic&#39;],<br>          requiredVersion: dependencies[&#39;@angular/platform-browser-dynamic&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/router&#39;: {<br>          version: dependencies[&#39;@angular/router&#39;],<br>          requiredVersion: dependencies[&#39;@angular/router&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/cdk/a11y&#39;: {<br>          version: dependencies[&#39;@angular/cdk/a11y&#39;],<br>          requiredVersion: dependencies[&#39;@angular/cdk/a11y&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>        &#39;@angular/animations&#39;: {<br>          version: dependencies[&#39;@angular/animations&#39;],<br>          requiredVersion: dependencies[&#39;@angular/animations&#39;],<br>          singleton: false,<br>          eager: true<br>        },<br>      }<br><br>    })<br>  ],<br>};</pre><p>In technical terms, we have configured the Module Federation for the host application. Now let’s add some code that implements the idea of the dynamics at runtime.</p><p>1. The next step: configuring the lazy route for the module loaded from a remote plugin.</p><p>2. Adding the<em> </em>Angular (v.<em>) component to the Angular (v</em>.)<em> host application.</em></p><p>3. Adding the React component to the Angular (v.*) host application.</p><p>To ensure the loading of a module from a remote plugin, we should know:</p><p>1. the remote plugin URL;</p><p>2. the remote plugin name (specified in library.name in webpack.config.js);</p><p>3. the name of the module, which we expose in the remote plugin;</p><p>4. the name of the Angular module to correctly load it in the loadChildren method;</p><p>5. the name of the Angular route to use in the host application;</p><p>6. a human-readable name for the text of the link that navigates to the loaded module.</p><p>As a result, there is such a configuration for a specific route:</p><pre>//sample-configuration.ts</pre><pre>export const ROUTES_CONFIGURATION: ReadonlyArray&lt;FederationPlugin&gt; = [<br>  {<br>    type: &#39;angular&#39;,<br>    subType: &#39;routeModule&#39;,<br>    remoteEntry: &#39;http://localhost:4201/remoteEntry.js&#39;,<br>    remoteName: &#39;angular_mfe_1&#39;,<br>    exposedModule: &#39;MfeModule&#39;,<br>    displayName: &#39;Notes&#39;,<br>    routePath: &#39;notes&#39;,<br>    moduleClassName: &#39;BusinessModule&#39;,<br>    navigationAlias: &#39;notesList&#39;<br>  },<br>  {<br>    type: &#39;angular&#39;,<br>    subType: &#39;routeModule&#39;,<br>    remoteEntry: &#39;http://localhost:4201/remoteEntry.js&#39;,<br>    remoteName: &#39;angular_mfe_1&#39;,<br>    exposedModule: &#39;MfeModule&#39;,<br>    displayName: &#39;Notes&#39;,<br>    routePath: &#39;notesOlga&#39;,<br>    moduleClassName: &#39;BusinessModule&#39;,<br>    navigationAlias: &#39;notesList&#39;<br>  },<br>  {<br>    type: &#39;angular&#39;,<br>    subType: &#39;routeModule&#39;,<br>    remoteEntry: &#39;http://localhost:4203/remoteEntry.js&#39;,<br>    remoteName: &#39;angular_mfe_3&#39;,<br>    exposedModule: &#39;NotesCounterModule&#39;,<br>    displayName: &#39;Notes Counter 12 Angular&#39;,<br>    routePath: &#39;notesCounter12Angular&#39;,<br>    moduleClassName: &#39;NotesCounterModule&#39;,<br>    navigationAlias: &#39;notesCounter12Angular&#39;<br>  }<br>];</pre><p>It is loaded when the application launches. Then, the routes in the application are updated.</p><pre>// federation-utils.ts</pre><pre>const appRoutes: Routes = <em>buildRoutes</em>(routes);<br>this.router.resetConfig(appRoutes);</pre><p>To make it clear, let’s take a look at the configuration of this plugin.</p><pre>new ModuleFederationPlugin({<br>  name: &quot;angular_mfe_1&quot;,<br>  library: {type: &quot;var&quot;, name: &quot;angular_mfe_1&quot;},<br>  filename: &quot;remoteEntry.js&quot;,<br>  exposes: {<br>    MfeModule: &quot;./src/app/modules/business-module/business.module.ts&quot;,<br>    BusinessComponent: &quot;./src/app/modules/business-module/business/business.component.ts&quot;<br>  },<br>  shared: {....}<br><br>})</pre><p>I guess we should not discuss the details of mapping configuration values onto the properties of the Module Federation plugin.</p><p>To use components written in other frameworks, you will need adapters. In our case, there are two of them: Angular in Angular and React in Angular.</p><p>The listing of the adapter over the Angular component is provided below. I doubt you will find any extraordinary lines there, because this solution is mostly based on<a href="https://angular.io/guide/dynamic-component-loader"> Angular official documentation</a> on dynamic component initialization. But if you don’t want to read the documentation again, just click the spoiler — you can find a ready-made solution over there.</p><pre>import {<br>  AfterContentInit,<br>  Compiler,<br>  Component,<br>  ComponentFactory,<br>  ComponentFactoryResolver,<br>  ComponentRef,<br>  EventEmitter,<br>  Injector,<br>  Input,<br>  Output,<br>  ViewChild,<br>  ViewContainerRef,<br>} from &#39;@angular/core&#39;;<br>import {<em>loadRemoteModule</em>} from &#39;../../utils/federation-utils&#39;;<br>import {FederationPlugin} from &#39;../../microfrontends/microfrontend.model&#39;;<br><br>@Component({<br>  selector: &#39;angular-mf-adapter&#39;,<br>  template: &#39;&lt;div class=\&#39;angular-mf-adapter\&#39;&gt;&lt;ng-container #container&gt;&lt;/ng-container&gt;&lt;/div&gt;&#39;<br>})<br>export class AngularWrapperComponent implements AfterContentInit {<br>  @Input() configuration: FederationPlugin;<br>  @Output() outputs: EventEmitter&lt;Record&lt;string, EventEmitter&lt;any&gt;&gt;&gt; = new EventEmitter();<br>  @ViewChild(&#39;container&#39;, {read: ViewContainerRef}) container: ViewContainerRef;<br>  inputsBeforeComponentCreate: Record&lt;string, unknown&gt; = {};<br>  inputsInternal: Record&lt;string, unknown&gt; = {};<br>  private componentReference: ComponentRef&lt;any&gt;;<br>  private isOutputsRegistered = false;<br>  private componentInputs: Array&lt;string&gt;;<br>  private componentOutputs: Array&lt;string&gt;;<br><br>  constructor(private componentFactoryResolver: ComponentFactoryResolver,<br>              private compiler: Compiler,<br>              private injector: Injector) {<br>  }<br><br>  @Input() set inputs(props: Record&lt;string, unknown&gt;) {<br>    this.inputsInternal = props;<br>    this.setProps();<br>  }<br><br>  async ngAfterContentInit(): Promise&lt;void&gt; {<br>    await this.renderComponent();<br>  }<br><br>  private async renderComponent(): Promise&lt;void&gt; {<br>    const configuration = this.configuration;<br>    if (configuration) {<br>      const component = await <em>loadRemoteModule</em>({<br>        remoteEntry: configuration.remoteEntry,<br>        remoteName: configuration.remoteName,<br>        exposedModule: configuration.exposedModule<br>      });<br><br>      switch (configuration.subType) {<br>        case &#39;componentModule&#39;: {<br>          this.compiler.compileModuleAndAllComponentsAsync(component[configuration.moduleClassName])<br>            .then(async (module) =&gt; {<br>              const moduleReference = module.ngModuleFactory.create(this.injector);<br>              const innerComponent = await <em>loadRemoteModule</em>({<br>                remoteEntry: configuration.remoteEntry,<br>                remoteName: configuration.remoteName,<br>                exposedModule: configuration.exposedComponent<br>              });<br>              <em>// TODO: Can cache compiled modules to reuse they in second time<br>              </em>const moduleInjectorComponentFactory = moduleReference<br>                .componentFactoryResolver<br>                .resolveComponentFactory(innerComponent[configuration.componentClassName]);<br>              this.saveInputsOutputs(moduleInjectorComponentFactory);<br>              if (moduleInjectorComponentFactory) {<br>                this.createComponent(moduleInjectorComponentFactory);<br>              }<br>            });<br>          break;<br>        }<br>        case &#39;component&#39;: {<br>          const componentFactory = this.componentFactoryResolver.resolveComponentFactory(component[configuration.componentClassName]);<br>          this.saveInputsOutputs(componentFactory);<br>          this.createComponent(componentFactory);<br>          break;<br>        }<br>      }<br>    }<br>  }<br><br>  private saveInputsOutputs(componentFactory: ComponentFactory&lt;unknown&gt;): void {<br>    this.componentInputs = componentFactory.inputs.map((input) =&gt; input.templateName);<br>    this.componentOutputs = componentFactory.outputs.map((output) =&gt; output.templateName);<br>  }<br><br>  private createComponent(componentFactory: ComponentFactory&lt;any&gt;): void {<br>    this.container.clear();<br>    this.componentReference = this.container.createComponent(componentFactory);<br>    this.setProps();<br>  }<br><br>  private setProps(): void {<br>    if (this.componentReference?.instance) {<br>      const eventEmitters: Record&lt;string, EventEmitter&lt;any&gt;&gt; = {};<br>      for (const propName in this.componentReference.instance) {<br>        if (this.componentOutputs.includes(propName)) {<br>          eventEmitters[propName] = this.componentReference.instance[propName];<br>        }<br>      }<br>      const props = {...this.inputsInternal, ...this.inputsBeforeComponentCreate};<br>      for (const propName in props) {<br>        if (this.componentInputs.includes(propName)) {<br>          this.componentReference.instance[propName] = props[propName];<br>          this.componentReference.changeDetectorRef.markForCheck();<br>        }<br>      }<br>      if (!this.isOutputsRegistered) {<br>        this.outputs.emit(eventEmitters);<br>        this.isOutputsRegistered = true;<br>      }<br>      this.inputsBeforeComponentCreate = {};<br>    } else {<br>      this.inputsBeforeComponentCreate = {<br>        ...this.inputsBeforeComponentCreate,<br>        ...this.inputsInternal<br>      };<br>    }<br>  }<br>}</pre><p>The adapter over the React component looks like this:</p><pre>import {AfterContentInit, Component, ElementRef, Input, OnDestroy} from &#39;@angular/core&#39;;<br>import React from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import {ActivatedRoute, Data} from &#39;@angular/router&#39;;<br>import {<em>take</em>} from &#39;rxjs/operators&#39;;<br>import {FederationPlugin} from &#39;../../../../microfrontends/microfrontend.model&#39;;<br>import {EventBusService} from &#39;../../../../microfrontends/event-bus.service&#39;;<br>import {GlobalNavigationService} from &#39;../../../../microfrontends/global-navigation.service&#39;;<br>import {<em>loadRemoteModule</em>} from &#39;../../../../utils/federation-utils&#39;;<br><br><br><br>@Component({<br>  selector: &#39;react-wrapper&#39;,<br>  template: &#39;&#39;,<br>  styles: [&#39;:host {height: 100%; overflow: auto;}&#39;]<br>})<br>export class ReactWrapperComponent implements AfterContentInit, OnDestroy {<br>  propsInternal: Record&lt;string, unknown&gt;;<br><br>  @Input() set props(props: Record&lt;string, unknown&gt;) {<br>    this.propsInternal = props;<br>    this.updateComponentProps(props);<br>  }<br><br>  @Input() configuration: FederationPlugin;<br><br>  private reactMFEModule;<br><br><br>  constructor(private hostRef: ElementRef,<br>              private route: ActivatedRoute,<br>              private eventBusService: EventBusService,<br>              private globalNavigationService: GlobalNavigationService<br>  ) {<br>  }<br><br>  async ngAfterContentInit(): Promise&lt;void&gt; {<br>    if (!this.configuration) {<br>      this.route.data<br>        .pipe(<em>take</em>(1))<br>        .subscribe(async (data: Data) =&gt; {<br>          const configuration: FederationPlugin = data.configuration;<br>          await this.renderComponent(configuration, data.props);<br>        });<br>    }<br>    await this.renderComponent(this.configuration, this.propsInternal);<br>  }<br><br>  private async renderComponent(configuration: FederationPlugin, props: Record&lt;string, unknown&gt;): Promise&lt;void&gt; {<br>    this.configuration = configuration;<br>    const component = await <em>loadRemoteModule</em>({<br>      remoteEntry: configuration.remoteEntry,<br>      remoteName: configuration.remoteName,<br>      exposedModule: configuration.exposedModule<br>    });<br>    this.reactMFEModule = component[configuration.moduleClassName];<br>    const ReactElement = React.createElement(<br>      this.reactMFEModule,<br>      this.constructProps({<br>        ...props,<br>        basename: this.configuration.routePath<br>      })<br>    );<br>    ReactDOM.render(ReactElement, this.hostRef.nativeElement);<br>  }<br><br>  ngOnDestroy(): void {<br>    ReactDOM.unmountComponentAtNode(this.hostRef.nativeElement);<br>  }<br><br>  private updateComponentProps(props: Record&lt;string, unknown&gt;): void {<br>    if (this.reactMFEModule) {<br>      const ReactElement = React.createElement(this.reactMFEModule, this.constructProps({<br>        ...props,<br>        basename: this.configuration.routePath<br>      }));<br>      ReactDOM.hydrate(ReactElement, this.hostRef.nativeElement);<br>    }<br>  }<br><br>  private constructProps(routeProps): Record&lt;string, unknown&gt; {<br>    if (!routeProps) {<br>      routeProps = {};<br>    }<br>    if (!this.propsInternal) {<br>      this.propsInternal = {};<br>    }<br><br>    return {...this.props, ...routeProps, eventBus: this.eventBusService, globalNavigation: this.globalNavigationService};<br>  }<br>}</pre><p>Additionally, for React to work in an Angular host application, you should add ProvidePlugin to the Webpack configuration:</p><pre><strong>new</strong> webpack.ProvidePlugin({&quot;React&quot;: &quot;react&quot;,}),</pre><p>We will write the plugin selection orchestrator so that in the configuration, you can specify, which framework was used to write the component/module. This will allow you to understand exactly which way of plugin initialization should be used. The scheme for building routes is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/1*44BDSMwQP8TAeTL2yqBadw.png" /></figure><p>And below you can find the code listing that we use for building routes according to the previously described scheme:</p><pre>export function <em>buildRoutes</em>(options: ReadonlyArray&lt;FederationPlugin&gt;): Routes {<br>  const lazyRoutes: Routes = options?.map((mfe: FederationPlugin) =&gt; {<br>    switch (mfe.type) {<br>      case &#39;angular&#39;: {<br>        switch (mfe.subType) {<br>          case &#39;routeModule&#39;: {<br>            return {<br>              path: mfe.routePath,<br>              loadChildren: () =&gt; <em>loadRemoteModule</em>(mfe).then((m) =&gt; m[mfe.moduleClassName]),<br>            };<br>          }<br>          default: {<br>            return {<br>              path: mfe.routePath,<br>              loadChildren: () =&gt; <em>loadRemoteModule</em>(mfe).then((m) =&gt; m[mfe.moduleClassName]),<br>            };<br>          }<br>        }<br>      }<br>      case &#39;react&#39;: {<br>        return {<br>          path: mfe.routePath,<br>          children: [<br>            {<br>              path: &#39;**&#39;,<br>              loadChildren: () =&gt; import(&#39;../modules/react-wrapper/react-wrapper.module&#39;).then((m) =&gt; {<br>                return m.ReactWrapperModule;<br>              }),<br>              data: {configuration: mfe},<br>            }<br>          ]<br>        };<br>      }<br>      case &#39;vue&#39;: {<br>        return {<br>          path: mfe.routePath,<br>          children: [<br>            {<br>              path: &#39;**&#39;,<br>              component: VueWrapperComponent,<br>              data: {configuration: mfe}<br>            }<br>          ]<br>        };<br>      }<br>      default: {<br>        return {<br>          path: mfe.routePath, <em>// TODO: add UnknownPluginType component to catch incorrect configuration<br>          </em>children: [<br>            {<br>              path: &#39;**&#39;,<br>              component: SelfRunWrapperComponent,<br>              data: {configuration: mfe}<br>            }<br>          ]<br>        };<br>      }<br>    }<br>  });<br><br>  return [...(lazyRoutes || []), ...APPLICATION_ROUTES];<br>}</pre><h3>Plugin Prototype</h3><p>The plugin will differ from the host application in just a couple of lines in webpack.config.js.</p><p>The exposes section deserves special attention. Here we specify the key names of the modules and paths to the classes implementing them. The class name and module name in the exposes section may be different.</p><pre>const ModuleFederationPlugin = <em>require</em>(&quot;webpack/lib/container/ModuleFederationPlugin&quot;);<br>const mf = <em>require</em>(&quot;@angular-architects/module-federation/webpack&quot;);<br>const path = <em>require</em>(&quot;path&quot;);<br>const dependencies = <em>require</em>(&quot;./package.json&quot;).dependencies;<br><br>const sharedMappings = new mf.SharedMappings();<br>sharedMappings.register(<br>  path.<em>join</em>(__dirname, &#39;tsconfig.json&#39;),<br>  [<em>/* mapped paths to share */</em>]);<br><br>module.exports = {<br>  output: {<br>    uniqueName: &quot;angular_mfe_1&quot;,<br>    publicPath: &quot;auto&quot;<br>  },<br>  module: {<br>    rules: [<br>      {<br>        test: /\.css$/i,<br>        use: [&quot;style-loader&quot;, &quot;css-loader&quot;],<br>      }<br>    ]<br>  },<br>  optimization: {<br>    runtimeChunk: false<br>  },<br>  resolve: {<br>    alias: {<br>      ...sharedMappings.getAliases(),<br>    }<br>  },<br>  plugins: [<br>    new ModuleFederationPlugin({<br>      name: &quot;angular_mfe_1&quot;,<br>      library: {type: &quot;var&quot;, name: &quot;angular_mfe_1&quot;},<br>      filename: &quot;remoteEntry.js&quot;,<br>      exposes: {<br>        MfeModule: &quot;./src/app/modules/business-module/business.module.ts&quot;,<br>        BusinessComponent: &quot;./src/app/modules/business-module/business/business.component.ts&quot;<br>      },<br>      shared: {<br>        &#39;@angular/common/http&#39;: {<br>          version: dependencies[&#39;@angular/common&#39;],<br>          requiredVersion: dependencies[&#39;@angular/common&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/common&#39;: {<br>          version: dependencies[&#39;@angular/common&#39;],<br>          requiredVersion: dependencies[&#39;@angular/common&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/core&#39;: {<br>          version: dependencies[&#39;@angular/core&#39;],<br>          requiredVersion: dependencies[&#39;@angular/core&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/platform-browser&#39;: {<br>          version: dependencies[&#39;@angular/platform-browser&#39;],<br>          requiredVersion: dependencies[&#39;@angular/platform-browser&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/platform-browser-dynamic&#39;: {<br>          version: dependencies[&#39;@angular/platform-browser-dynamic&#39;],<br>          requiredVersion: dependencies[&#39;@angular/platform-browser-dynamic&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/router&#39;: {<br>          version: dependencies[&#39;@angular/router&#39;],<br>          requiredVersion: dependencies[&#39;@angular/router&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/cdk/a11y&#39;: {<br>          version: dependencies[&#39;@angular/cdk/a11y&#39;],<br>          requiredVersion: dependencies[&#39;@angular/cdk/a11y&#39;],<br>          singleton: true,<br><br>        },<br>        &#39;@angular/animations&#39;: {<br>          version: dependencies[&#39;@angular/animations&#39;],<br>          requiredVersion: dependencies[&#39;@angular/animations&#39;],<br>          singleton: true,<br><br>        }<br>      }<br><br>    }),<br>  ],<br>};</pre><p><strong>Specifics</strong></p><p>The `uniqueName` property should have a unique name throughout the application, otherwise, there will be problems when loading plugins. In our case, the `publicPath` property should have the auto value as URL to our plugins is set in the dynamic configuration and we do not know it when building the application.</p><pre>output: {<br>  uniqueName: &quot;angular_mfe_1&quot;,<br>  publicPath: &quot;auto&quot;<br>}</pre><h3>Support</h3><p>One year after the Module Federation release, we came up with the question about Webpack 5 support in angular-cli. Currently, the experimental support has been added in Angular 12.</p><p>As for the projects created using <a href="https://github.com/facebook/create-react-app">CRA</a>, <strong>react-scripts do not support Webpack 5</strong> now. To create the Module Federation in these projects, we need to do the react-scripts eject to be able to change webpack.config.js.</p><p>You can monitor the progress of migrating to Webpack 5 in react-scripts at <a href="https://github.com/facebook/create-react-app/issues/9994">github.com</a>. When studying the seamless migration to the Module Federation in react-scripts projects, I came across some <a href="https://www.npmjs.com/package/react-app-rewired">react-app-rewired</a> or <a href="https://github.com/gsoft-inc/craco">craco</a> solutions for partial changing the Webpack configuration. But they did not work :( We are waiting for the full support in react-scripts!</p><h3>Improvement Plans</h3><p>Our prototype turned out to be well-functioning but there are still many ways to develop our idea. The things we are planning to do in the nearest future:</p><p>1. Add processing of non-existing plugin type;</p><p>2. Add recursion for nested routes;</p><p>3. Write a bus for communication between plugins;</p><p>4. Correctly handle the case of navigation between fragments without hardcoding;</p><p>5. Add adapter for the Vue components;</p><p>6. Develop a validator for checking the uniqueness of the plugin names and intersection of dependencies to optimize the bundle.</p><p>Feel free to share your feedback, ideas, and information on how you are dealing with it in the comments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bd426e996da" width="1" height="1" alt=""><hr><p><a href="https://medium.com/netcracker/webpack-module-federation-micro-frontend-powered-by-modern-technologies-8bd426e996da">Webpack Module Federation: Micro-Frontend Powered by Modern Technologies</a> was originally published in <a href="https://medium.com/netcracker">netcracker</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Webpack module federation microfrontends. Use it to the fulltest.]]></title>
            <link>https://medium.com/@i.s.isupov/webpack-module-federation-microfrontends-use-it-to-the-fulltest-9a712ae83683?source=rss-df9702fe676d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9a712ae83683</guid>
            <category><![CDATA[module-federation]]></category>
            <category><![CDATA[webpack-5]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[microservice-architecture]]></category>
            <dc:creator><![CDATA[Ilya Isupov]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 21:15:29 GMT</pubDate>
            <atom:updated>2021-09-03T21:15:29.767Z</atom:updated>
            <content:encoded><![CDATA[<p>There are too many ways to develop microfrontends in 2021. But have you ever seen the really best handy way to create super large application created by several teams includes more than 300+ developers?</p><h3>Goals</h3><p>The main idea consist of several points.</p><ol><li>Ability to dynamically load components in runtime.</li><li>Components and application parts includes its should be developed by separate teams.</li><li>Teams should have independent cycles of components release.</li><li>All components should be re-usable by other application parts/teams.</li><li>Lazy runtime component may be implemented by any framework/lib</li></ol><h3>Approach</h3><p>Webpack module federation gives us a really cool ability to develop large applications based on microfrontend pattern. I mean local development, all goals coverage and industrially-wide approach.</p><p>Let’s move closer to implementation details. As a base approach I plan to use adapter pattern to make it possible use components implemented based on separate frameworks/libs and use its in code like super natively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BNEONHGqN3RU4aUMefSAog.png" /></figure><p><strong>What does it mean ‘super natively’?</strong></p><p>It means I want to write components in code as everyone get used to write. For example in angular application I write components like here:</p><pre>&lt;notes-counter [notes]=&quot;_notes&quot;&gt;&lt;/notes-counter&gt;</pre><p>In target solution it can be wrote like this:</p><pre>&lt;angular-mf-adapter <br>                 [configuration]=&quot;widgetConfiguration&quot;<br>                 [inputs]=&quot;widgetInputs$ | async&quot;<br>                 (outputs)=&quot;_onRegisterOutputs($event)&quot;<br>&gt;&lt;/angular-mf-adapter&gt;</pre><p>This is a little new expenses to use so dynamic microfrontend but it can be very useful to build a target architecture.</p><pre>widgetInputs$: Observable&lt;Record&lt;string, any&gt;&gt;</pre><p>Widget inputs are adopt through record and all input properties of target component will be set like this object:</p><pre>{<br>   notes: this.notes<br>}</pre><p>And all outputs of target component we can register in host component the handler below. Where object key is output name, value is event emitter instance.</p><pre>_onRegisterOutputs(outputs: Record&lt;string, EventEmitter&lt;any&gt;&gt;): void</pre><p>This approach give us an ability use target dynamically loaded in runtime components as native host components.</p><p><strong>Angular adapter</strong></p><pre>@Component({<br>  selector: &#39;angular-mf-adapter&#39;,<br>  template: &#39;&lt;div class=\&#39;angular-mf-adapter\&#39;&gt;&lt;ng-container #container&gt;&lt;/ng-container&gt;&lt;/div&gt;&#39;<br>})<br>export class AngularWrapperComponent implements AfterContentInit {<br>  @Input() configuration: FederationPlugin;<br>  @Output() outputs: EventEmitter&lt;Record&lt;string, EventEmitter&lt;any&gt;&gt;&gt; = new EventEmitter();<br>  @ViewChild(&#39;container&#39;, {read: ViewContainerRef}) container: ViewContainerRef;<br>  _inputsBeforeComponentCreate: Record&lt;string, unknown&gt; = {};<br>  private componentReference: ComponentRef&lt;any&gt;;<br>  private isOutputsRegistered: boolean = false;<br><br>  private componentInputs: Array&lt;string&gt;;<br>  private componentOutputs: Array&lt;string&gt;;<br><br>  constructor(private componentFactoryResolver: ComponentFactoryResolver,<br>              private compiler: Compiler,<br>              private injector: Injector) {<br>  }<br><br>  _inputs: Record&lt;string, unknown&gt; = {};<br><br>  @Input() set inputs(props: Record&lt;string, unknown&gt;) {<br>    this._inputs = props;<br>    this.setProps();<br>  }<br><br>  async ngAfterContentInit(): Promise&lt;void&gt; {<br>    await this.renderComponent();<br>  }<br><br>  private async renderComponent(): Promise&lt;void&gt; {<br>    const configuration = this.configuration;<br>    if (configuration) {<br>      const component = await <em>loadRemoteModule</em>({<br>        remoteEntry: configuration.remoteEntry,<br>        remoteName: configuration.remoteName,<br>        exposedModule: configuration.exposedModule<br>      });<br><br>      switch (configuration.subType) {<br>        case &#39;component-module&#39;: {<br>          this.compiler.compileModuleAndAllComponentsAsync(component[configuration.moduleClassName])<br>            .then(async (module) =&gt; {<br>              const moduleFactory = module.ngModuleFactory.create(this.injector);<br>              const innerComponent = await <em>loadRemoteModule</em>({<br>                remoteEntry: configuration.remoteEntry,<br>                remoteName: configuration.remoteName,<br>                exposedModule: configuration.exposedComponent<br>              });<br>              const moduleInjectorComponentFactory = moduleFactory.componentFactoryResolver.resolveComponentFactory(innerComponent[configuration.componentClassName]);<br>              this.saveInputsOutputs(moduleInjectorComponentFactory);<br>              if (moduleInjectorComponentFactory) {<br>                this.createComponent(moduleInjectorComponentFactory);<br>              }<br>            });<br>          break;<br>        }<br>        case &#39;component&#39;: {<br>          const componentFactory = this.componentFactoryResolver.resolveComponentFactory(component[configuration.moduleClassName]);<br>          this.saveInputsOutputs(componentFactory);<br>          this.createComponent(componentFactory);<br>          break;<br>        }<br>      }<br>    }<br>  }<br><br>  private saveInputsOutputs(componentFactory: ComponentFactory&lt;unknown&gt;): void {<br>    this.componentInputs = componentFactory.inputs.map((input) =&gt; input.templateName);<br>    this.componentOutputs = componentFactory.outputs.map((output) =&gt; output.templateName);<br>  }<br><br>  private createComponent(componentFactory: ComponentFactory&lt;any&gt;): void {<br>    this.container.clear();<br>    this.componentReference = this.container.createComponent(componentFactory);<br>    this.setProps();<br>  }<br><br>  private setProps(): void {<br>    if (this.componentReference?.instance) {<br>      const eventEmitters: Record&lt;string, EventEmitter&lt;any&gt;&gt; = {};<br>      for (const propName in this.componentReference.instance) {<br>        if (this.componentOutputs.includes(propName)) {<br>          eventEmitters[propName] = this.componentReference.instance[propName];<br>        }<br>      }<br>      const props = {...this._inputs, ...this._inputsBeforeComponentCreate};<br>      for (const propName in props) {<br>        if(this.componentInputs.includes(propName))<br>        {<br>          this.componentReference.instance[propName] = props[propName];<br>          this.componentReference.changeDetectorRef.markForCheck();<br>        }<br>      }<br>      if(!this.isOutputsRegistered) {<br>        this.outputs.emit(eventEmitters);<br>        this.isOutputsRegistered = true;<br>      }<br>      this._inputsBeforeComponentCreate = {};<br>    } else {<br>      this._inputsBeforeComponentCreate = {<br>        ...this._inputsBeforeComponentCreate,<br>        ...this._inputs<br>      };<br>    }<br>  }<br>}</pre><p>This adapter can be used in two ways. If we want to get a component from module (components with dependencies) and second way is to get stupid component.</p><p><strong>Component from module</strong></p><p>I think it’s time to take a look at widget descriptor (configuration).</p><pre>notesPlugin: {<br>  remoteEntry: &#39;https://localhost:4201/remoteEntry.js&#39;, //url only for local development, in production solution please use CDN<br>  remoteName: &#39;notes_list_widget&#39;,<br>  moduleClassName: &#39;NotesListWidgetModule&#39;,<br>  exposedModule: &#39;NotesListWidgetModule&#39;,<br>  subType: &#39;component-module&#39;,<br>  exposedComponent: &#39;NotesListWidget&#39;,<br>  componentClassName: &#39;NotesListWidgetComponent&#39;<br>}</pre><p>The most interested here is named properties: moduleClassName, componentClassName, exposedModule and exposedComponent. Exposed properties are set by yourself in webpack.config.js file:</p><pre>name: &quot;notes_list_widget&quot;,<br>library: {<br>    type: &quot;var&quot;,<br>    name: &quot;notes_list_widget&quot;<br>},<br>filename: &quot;remoteEntry.js&quot;,<br>exposes: {<br>    NotesListWidgetModule: &quot;./src/app/widgets/notes-widget/notes-widget.module.ts&quot;,<br>    NotesListWidget: &quot;./src/app/widgets/notes-widget/components/notes-widget.component.ts&quot;,<br>},</pre><p>Class names are real names of classes implements exposed modules. Let’s take a look at processing flow diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/579/1*NvqHwFMwDFhs4-DevIu8Uw.png" /></figure><p>Based on this we can eject any component from any module.</p><p><strong>Stupid component</strong></p><p>Ejecting stupid component seems like ejecting component from module but simpler. We don’t need to set injector because stupid component doesn’t have dependencies.</p><h3>Post benefits</h3><p>At the end of this post we have a working example with host application and several remote widgets. I created a little repository with working code <a href="https://github.com/ilya-isupov/multi-framework-module-federation">Multi framework module federation example.</a></p><p>Feel free to discuss the current approach. May be you are more experienced in module federation.</p><p>Good day :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9a712ae83683" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>