mercedes-benz / mo360-ftk

MO360 Frontend Toolkit: A toolkit for single page applications (SPA) based on React and Typescript that allows to extract single features into microfrontends.
https://mercedes-benz.github.io/mo360-ftk/
MIT License
70 stars 20 forks source link

Wmf #46

Closed mbeckert closed 2 years ago

mbeckert commented 3 years ago

WMF

host-app

webpack/base.js

ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
[...]
new ModuleFederationPlugin({
  name: 'host',
  remotes: {},
  shared: Object.keys(packageJson.dependencies),
}),

src/routes/Home.tsx <SwidgetLoader url="http://127.0.0.1:7070/swidgetEntry.js" scope="swidget" module="app" />

swidget-app

webpack/base.js

ModuleFederationPlugin = require("webpack/lib/container/ModuleFederationPlugin");
[...]
new ModuleFederationPlugin({
  name: 'swidget',
  filename: "swidgetEntry.js",
  exposes: {
    'app': './src/App',
  },
  shared: Object.keys(packageJson.dependencies),
}),

router

route-declaration

NEW

container.bind<RouteConfigType>(serviceIds.routes).toConstantValue([
    {
      name: 'home',
      path: '',
      action: () => {
        return () => <h1>Hello World</h1>
      },
    }
  ]);

OLD

  container.bind<IRouteConfig[]>(serviceIds.routes).toConstantValue([
    {
      component: () => <h1>Hello World</h1>,
      name: 'home',
      pattern: '/',
    },
  ]);

service

mbeckert commented 3 years ago

successfully tested the new core with the following test-scenarios considering old (classic hotloader) and new boilerplate (webpack5 wmf) - in DEV and PROD env.

test-scenario DEV classic hotloading PROD classic hotloading DEV webpack module federation PROD webpack module federation
nested routing
swidget has further dependency (unknown to host)
swidget consumes DI Binding from host
swidget re-binds DI Binding from host
interconnection between host and swidget
BlackDark commented 2 years ago

@mbeckert rebase please to resolve conflicts

prode81 commented 2 years ago

First findings: