Giter Club home page Giter Club logo

mfe-base's Introduction

Micro FrontEnds Baseline Project

A Demo project exploring options of dynamic loading of micro-frontends on the shell

Get started

yarn install

yarn run start

Open browser to

http://localhost:3001/workspaces

this will currently only run in dev mode on webpack-dev-server.

Production bundling could be added later on, by deploying prod builds into private CDN locations (AWS S3 buckets)

Approach

Each app is implemented in a monorepo, along with shell as the host

Shell has import-map module reference to each app bundle

Each app is hosted on a sub path (/app1, /app2) using react-router-dom

Each app is lazy loaded when specific route to that app is called, apps depend on Shell libraries

Webpack-dev-server compiles each app as SystemJS libraries and starts webservers on different ports to host app bundles

package dev hosting location
shell http://localhost:3001
react-app1 http://localhost:3002
svelte-app2 http://localhost:3003

Features

ESM Modules?

Is the present and the future. Most browsers natively support loading ESM modules nowadays. This below works in a browser console.

const React = await import('https://cdn.jsdelivr.net/npm/@esm-bundle/react/esm/react.production.min.js');

However, most libraries are not published in ESM modules format, lodash, react ...

Webpack takes care of CommonJS format to make it work with import /export syntax in browsers.

Webpack 5 may provide bundling in ESM format soon

Why can I not use native ESM Modules?

On every module you'd have to pass the absolute path of Import CDN Url ๐Ÿ˜ 

ESM native importmap feature could solve this at the top of the home page

<script type="importmap">

  imports: {
    vue: "https://unpkg.com ... /vue.esm.browser.min.js"
    react: "https:// ..."
    lodash:"..."
  }

</script>

Not all browsers support importmaps though. ๐Ÿ˜•

So comes SystemJS to the rescue

Watch this for justification of SystemJS https://www.youtube.com/watch?v=AmdKF2UhFzw

SystemJS - feat/systemjs-modules

The way to configure in webpack

  output: {
    filename: 'shell-bundle.js',
    libraryTarget: 'system',
  },

Shared State

You can use

libraries to utilise a shared state management in the shell

mfe-base's People

Contributors

bgorkem avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.