5 Costly Mistakes New Online Entrepreneurs Make With PPC Advertising

Something I have seen time and time again are these amazing entrepreneurs with a wealth of knowledge and years of industry experience. They have seen a problem or an opportunity and work tirelessly…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Angular Directive to load a federated remote module

We have tried lazy loading modules and components in Angular. But what about loading a federated module instead? In this article, we’re going to create a directive which can fetch and render a remote module exposed from a different application into the so called “host” app.

In the past, tools like Webpack assume that the entire program code is available when compiling. And we can split a module like this and lazy load it, but still, that is known from the angular compiler while building the code. But what we want to do is load program parts which are not known at compile time. Webpack 5 finally enabled us to do such a thing. A “federated module” in the microfrontend world is an Angular module, which can be federated by a remote app and imported into the host app, but the host application doesn’t know anything about it in the compile time. So this means faster builds, small bundle applications and of course, faster times painting of the script in the browser.

In my last article of the microfrontend series, we were able to load a remote exposed module from a remote app into the host application using angular routing and module federation plugin.

loadRemoteModule function requires 3 parameters:

2. In your remote app webpack config you should expose the module like below:

3. In your host application make sure to import the exposed remote module like below:

4. The loaded() is an emmiter that can be used to show any loading state you want while the federated module is being fetched and prepared from the directive.

5. Make sure to run both apps. You can run them separately or use the below command to run all apps in parallel. This is useful when you don’t have many applications in your monorepo. Keep in mind that if you make changes to the webpack.config.js file, you need to restart the respective application, since it's not part of the hot reloading strategy.

As usual, thank you for reading. I appreciate the time you take to read my content and stories. I hope you can find this post useful.
Stay tuned and happy coding!

Add a comment

Related posts:

Top 5 Benefits of Aloe Vera Juice

Aloe vera is a succulent plant that is known for its numerous medicinal and healing properties. It has been used for centuries in traditional medicine to treat a wide range of ailments. Aloe vera…

Weekend with My Family

It was awesome to be able to see my parents for the first time since early August. They were able to make it to Charlotte on Friday to watch my race, and then we got to spend the entire day Saturday…