Building A Shell Application for Micro Frontends | Part 4

In this post, we will create the last piece of our micro frontends with the design system PoC.

In this post, we will create the last piece of our micro frontends with the design system PoC. We now have a design system, several micro frontends consuming this design system, and we need now a shell application that will import micro frontends and display them.

Shell Application Overview

This shell application will import micro frontends using script tags and script URLs hardcoded in index.html in the real project, it would be driven by some sort of configuration.

Aspects Not Covered

This series will not cover two aspects: module federation and mounting microseconds to isolated virtual DOM.

Understanding Module Federation

Module federation helps to lower the size of included script by requesting modules, used by more than one micro frontend, only once. If we want to increase isolation between micro frontend we can create a web component that will mount micro frontend to isolated virtual dom.

 

Setting Up the Shell Application

Create directory fitness-portal-shell in the same directory as design-system and micro frontends.

Running Setup Commands

Run the following commands, from the new directory to setup project dependencies:

npm init -y
npm i -P react@17.0.2 react-dom@17.0.2 react-hot-loader@4.13.0
npm i -D webpack@5.38.1 webpack-cli@4.7.0 webpack-dev-server@3.11.2  html-webpack-plugin@5.3.1 cross-env@7.0.3 babel-loader@8.2.2 @hot-loader/react-dom@17.0.1+4.13.0  @babel/preset-react@7.13.13 @babel/preset-env@7.14.4 @babel/core@7.14.3 mini-css-extract-plugin@1.6.0 css-loader@5.2.6

Now we need a few files.

Create file ./src/App.js with the following content:

import React from "react";
import    from "react-hot-loader/root";
import MicroFrontend from "./MicroFrontend";

class App extends React.Component {
  render() {
    return [
        "nutritionPortal",
        // Uncomment following lines if you created additional micro frontends
        // "exercisePortal",
        // "mealsPlannerPortal",
        // "recipesPortal"
    ].map((name) => (
      
    ));
  }
}

export default hot(App);

Create file ./src/MicroFrontend.js with the following content:

import React,    from 'react'

export default class MicroFrontend extends Component {

    get containerId() {
        return `mf-$
    

    render() {
        return 

Create file ./src/index.js with the following content:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";

var mountNode = document.getElementById("app");
ReactDOM.render(, mountNode);

Create file ./src/index.html with the following content:





    
    
    
    
    
    


    

    



    

This is a naive implementation where we hard-code links to micro frontends' resources in a real project it would come from the configuration.

No we will configure build.

Create file ./.bablrc with the following content:

{
    presets: [
      [
        '@babel/preset-env',
        {
          modules: false
        }
      ],
      '@babel/preset-react'
    ],
    plugins: [
      'react-hot-loader/babel'
    ]
  }

Create file ./webpack.config.js with the following content:

const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");

const config = {
  entry: ["react-hot-loader/patch", "./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        use: "babel-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
            },
          },
        ],
      },
    ],
  },
  resolve: {
    extensions: [".js"],
    alias: {
      "react-dom": "@hot-loader/react-dom",
    },
  },
  devServer: {
    contentBase: "./src",
    watchContentBase: true,
    port: 7000,
    headers: {
      "Access-Control-Allow-Origin": "*",
      "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS"
    },
  },
  plugins: [
    new HtmlWebpackPlugin({
      template: "./src/index.html",
    }),
    new MiniCssExtractPlugin(),
  ],
  optimization: {
    runtimeChunk: "single",
    splitChunks: {
      cacheGroups: {
        vendor: {
          test: /[\\/]node_modules[\\/]/,
          name: "vendors",
          chunks: "all",
        },
      },
    },
  },
};

module.exports = (env, argv) => {
  if (argv.hot) {
    // Cannot use 'contenthash' when hot reloading is enabled.
    config.output.filename = "[name].js";
  }

  return config;
};


Open ./package.json and add following script to scripts section:

"start": "cross-env NODE_ENV=development webpack serve --hot --mode development"

You should be able to build the shell app now. Run npm start. It should bind to port 7000. Remember to build and run micro frontends first.

Blog 7/15/21

Building a micro frontend consuming a design system | Part 3

In this blopgpost, you will learn how to create a react application that consumes a design system.

Blog 7/13/21

Composite UI with Design System and Micro Frontends

Discover how to create scalable composite UIs using design systems and micro-frontends. Enhance consistency and agility in your development process.

Headerbild zu Smart Insurance Workflows
Service

Smart Insurance Workflows

Using a design thinking approach, we orient workflows to the customer experience and design customer-centric end-to-end processes.

Blog 7/14/21

Building and Publishing Design Systems | Part 2

Learn how to build and publish design systems effectively. Discover best practices for creating reusable components and enhancing UI consistency.

Service

Training & Coaching

We offer a wide range of training and coaching services tailored to your individual needs.

Blog

Crisis management & building a sustainable future with AI

Non-profit organizations develop AI models to tackle global challenges - and draw lessons for businesses worldwide

Haderbild zu IBM Cloud Pak for Application
Technologie

IBM Cloud Pak for Application

The IBM Cloud Pak for Application provides a solid foundation for developing, deploying and modernising cloud-native applications. Since agile working is essential for a faster release cycle, ready-made DevOps processes are used, among other things.

Blog 10/1/22

Introduction to Functional Programming in F# – Part 4

Unlock F# collections and pipelines. Manage data efficiently and streamline your functional programming workflow with these powerful tools.

Service

Decision Automation

We offer a comprehensive service in the field of decision automation, ranging from consulting and design to implementation and operation

News 1/10/25

A new chapter for catworkx US

catworkx opens a new chapter in the USA: Nick Howser is our new CEO! With 13+ years in the Atlassian ecosystem and a strong focus on customer success, he will drive growth in the US.

Unternehmen

How we work

We think of ourselves as a tour guide for our clients. In this role we want to ensure that the digitalization adventure is a long-term success, because we believe that digitalization is not a one-off event, but a longer journey in a constantly changing world where you need to keep adapting.

Produkt 4/11/23

Idea management software for local applications

Idea management software with SAP technology: Optimize your idea management for more participation and greater benefits.

senior man stares through glasses
Lösung 8/31/23

Anthos integration for consistent cloud-native applications

Discover Anthos, the cloud-based container platform that runs modern apps consistently and scalably everywhere. CLOUDPILOTS supports you with seamless integration.

Blog 11/27/23

Part 4: Save Time and Analyze the Database File

ChatGPT-4 enables you to analyze database contents with just two simple steps (copy and paste), facilitating well-informed decision-making.

Blog 6/24/21

Using a Skill/Will matrix for personal career development

Discover how a Skill/Will Matrix helps employees identify strengths and areas for growth, boosting personal and professional development.

Blog 12/19/22

Creating a Cross-Domain Capable ML Pipeline

As classifying images into categories is a ubiquitous task occurring in various domains, a need for a machine learning pipeline which can accommodate for new categories is easy to justify. In particular, common general requirements are to filter out low-quality (blurred, low contrast etc.) images, and to speed up the learning of new categories if image quality is sufficient. In this blog post we compare several image classification models from the transfer learning perspective.

Blog 11/3/22

Inbox helps to clear the mind

I hate distractions. They can easily ruin my day when I'm in the middle of working on a cool project. They do that by overloading my mind, buzzing around inside me, and just making me tired. Even though we can think about several things at once, we can only do one thing at a time.

Unternehmen

TIMETOACT

TIMETOACT is a specialist for consulting and application development based on IBM software and open standards. The focus of our consulting services is on information architecture design, application and system architectures.

Blog 11/24/23

Part 3: How to Analyze a Database File with GPT-3.5

In this blog, we'll explore the proper usage of data analysis with ChatGPT and how you can analyze and visualize data from a SQLite database to help you make the most of your data.

Technologie

Pimcore als Open Source Software Platform

Pimcore is a free-to-use open source software platform and is already used effectively in many corporate fields. With Pimcore, your classic day-to-day business problems with portals and websites are easily solved as we tailor the platform to your specific business requirements.

Bleiben Sie mit dem TIMETOACT GROUP Newsletter auf dem Laufenden!