<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ruben</title>
    <description>The latest articles on DEV Community by Ruben (@ruben2079).</description>
    <link>https://dev.to/ruben2079</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2505037%2F7d76b174-730f-411b-a883-8b2590770994.png</url>
      <title>DEV Community: Ruben</title>
      <link>https://dev.to/ruben2079</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ruben2079"/>
    <language>en</language>
    <item>
      <title>How to load an MFE module from a shell app (Using Angular + Webpack + Module Federation)?</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Sat, 30 Nov 2024 21:09:05 +0000</pubDate>
      <link>https://dev.to/ruben2079/how-to-load-an-mfe-module-from-a-shell-app-using-angular-webpack-module-federation-53e6</link>
      <guid>https://dev.to/ruben2079/how-to-load-an-mfe-module-from-a-shell-app-using-angular-webpack-module-federation-53e6</guid>
      <description>&lt;p&gt;Hi everyone, I have question for you. Do you know how load an MFE (micro front end)  remote app, as a module from a shell app? when I try to do so there is an infinite loop. and the module from the MFE does not show. Any tips or ideas on how to accomplish this issue? (Using Angular + Webpack + Module Federation)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// webpack.config.js--SHELL APP 

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const path = require("path");

module.exports = {
    output: {
        uniqueName: "portalWebApp",
        publicPath: "auto",
        scriptType: "text/javascript",
    },
    optimization: {
        runtimeChunk: false,
    },
    resolve: {
        alias: {},
    },
    module: {
        rules: [{
            test: /\.html$/,
            use: ["html-loader"],
        }, ],
    },
    experiments: {
        outputModule: true,
    },
    plugins: [
        new ModuleFederationPlugin({
            // For remotes (please Add this 5 Line)
            name: "portalWebApp",
            filename: "remoteEntry.js",
            remotes: {
                astrPortFolioMasterWebApp: "astrPortFolioMasterWebApp@http://localhost:3002/remoteEntry.js",
                mfe1: "mfe1@http://localhost:4001/remoteEntry.js",
            },

            shared: {
                "@angular/core": {
                    singleton: true,
                    strictVersion: true,
                    eager: true
                },
                "@angular/common/": {
                    singleton: true,
                    strictVersion: true,
                    eager: true,
                },
                "@angular/router": {
                    singleton: true,
                    strictVersion: true,
                    eager: true,
                }
                // react: { singleton: true, eager: true },
                // "react-dom": { singleton: true, eager: true },
            },
        }),
    ],
};

// webpack.config.js--SHELL APP--END

// SHELL APP - Route

import { loadRemoteModule } from '@angular-architects/module-federation';
import { WebComponentWrapper, WebComponentWrapperOptions } from '@angular-architects/module-federation-tools';
import { Routes } from '@angular/router';
import { MsalGuard } from '@azure/msal-angular';
// import { MsalGuard } from '@azure/msal-angular';
// import { UserNotAllowedComponent } from './layout/user-not-allowed/user-not-allowed.component';
// import { ServerErrorComponent } from './layout/server-error/server-error.component';

export const routes: Routes = [{
        path: '',
        pathMatch: 'full',
        loadChildren: () =&amp;gt;
            import('./content-providers/content-provider.module').then(
                (m) =&amp;gt; m.ContentProviderModule
            ),
        canActivate: [MsalGuard],
    },
    {
        path: 'mfe1',
        loadChildren: () =&amp;gt; {
            return loadRemoteModule({
                    type: 'module',
                    remoteEntry: 'http://localhost:4001/remoteEntry.js',
                    exposedModule: './OrderModule',
                })
                .then((m) =&amp;gt; m.OrderModule)
                .catch((e) =&amp;gt; console.log(e));
        },
    },
    {
        path: 'astrPortFolioMasterWebApp',
        loadChildren: () =&amp;gt; {
            return loadRemoteModule({
                    type: 'module',
                    remoteEntry: 'http://localhost:3002/remoteEntry.js',
                    exposedModule: './astrPortFolioMasterWebAppModule',
                })
                .then((m) =&amp;gt; m.astrPortFolioMasterWebAppModule)
                .catch((e) =&amp;gt; console.log(e));
        },
    },
    {
        path: 'angular1',
        component: WebComponentWrapper,
        data: {
            remoteEntry: 'https://nice-grass-018f7d910.azurestaticapps.net/remoteEntry.js',
            remoteName: 'angular1',
            exposedModule: './web-components',
            elementName: 'angular1-element',
        }
        as WebComponentWrapperOptions,
    },
    {
        path: 'react1',
        component: WebComponentWrapper,
        data: {
            remoteEntry: 'https://witty-wave-0a695f710.azurestaticapps.net/remoteEntry.js',
            remoteName: 'react',
            exposedModule: './web-components',
            elementName: 'react-element',
        }
        as WebComponentWrapperOptions,
    },
    {
        path: 'vue',
        component: WebComponentWrapper,
        data: {
            remoteEntry: 'https://mango-field-0d0778c10.azurestaticapps.net/remoteEntry.js',
            remoteName: 'vue',
            exposedModule: './web-components',
            elementName: 'vue-element',
        }
        as WebComponentWrapperOptions,
    },
];


// SHELL APP - Route 

// webpack.config.js--MFE / REMOTE APP 

const ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
const { shareAll, SharedMappings } = require("@angular-architects/module-federation/webpack");
const Path = require("path");
const sharedMappings = new SharedMappings();

sharedMappings.register(
    Path.join(__dirname, 'tsconfig.json'), []
)
module.exports = {
    output: {
        uniqueName: "astrPortFolioMasterWebApp",
        publicPath: "auto",
        scriptType: "text/javascript",
    },
    optimization: {
        runtimeChunk: false
    },
    resolve: {
        alias: {
            ...sharedMappings.getAliases(),
        }
    },
    experiments: {
        outputModule: true
    },
    plugins: [
        new ModuleFederationPlugin({

            // For remotes (please Add this 5 Line)
            name: "astrPortFolioMasterWebApp",
            filename: "remoteEntry.js",
            exposes: {
                './astrPortFolioMasterWebAppModule': './src/app/layout/layout.module.ts',
            },

            shared: {
                "@angular/core": {
                    singleton: true,
                    strictVersion: true,
                    eager: true
                },
                "@angular/common/": {
                    singleton: true,
                    strictVersion: true,
                    eager: true
                },
                "@angular/router": {
                    singleton: true,
                    strictVersion: true,
                    eager: true
                },
            }
        }),
        sharedMappings.getPlugin()
    ]
};

// webpack.config.js--MFE / REMOTE APP - END 

// MFE - Remote - Route 

import { Routes } from '@angular/router';
import { MsalGuard } from '@azure/msal-angular';
import { UserNotAllowedComponent } from './layout/user-not-allowed/user-not-allowed.component';
import { ServerErrorComponent } from './layout/server-error/server-error.component';

export const routes: Routes = [
    // {
    //   path: '',
    //   pathMatch: 'full',
    //   redirectTo: 'portfolio'
    // },
    {
        path: 'portfolio',
        loadChildren: () =&amp;gt;
            import('./layout/layout.module').then((m) =&amp;gt; m.MainLayoutModule),
        canActivate: [MsalGuard]
    },

    {
        path: 'usernotallowed',
        component: UserNotAllowedComponent,
    },

    {
        path: '**',
        component: ServerErrorComponent,
    },
];

// MFE - Remote - Route - END 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>angular</category>
      <category>webpack</category>
      <category>microfrontend</category>
      <category>modulefederation</category>
    </item>
    <item>
      <title>Hi everyone, I have question for you. Do you know how load an MFE (micro front end) / remote app, as a module from a shell app? What I try to do so there's an infinite loop. and the module from the MFE does not show. Any ideas?</title>
      <dc:creator>Ruben</dc:creator>
      <pubDate>Sat, 30 Nov 2024 20:50:47 +0000</pubDate>
      <link>https://dev.to/ruben2079/hi-everyone-i-have-question-for-you-do-you-know-how-load-an-mfe-micro-front-end-remote-app-4cmo</link>
      <guid>https://dev.to/ruben2079/hi-everyone-i-have-question-for-you-do-you-know-how-load-an-mfe-micro-front-end-remote-app-4cmo</guid>
      <description></description>
      <category>webdev</category>
      <category>frontend</category>
      <category>discuss</category>
    </item>
  </channel>
</rss>
