A micro frontend application for cyclops web frontend.
-
Creating microfrontend app
npx create-mf-app
> NAME_OF_APP > Application > PORT_NUM > typescript > CSS
-
Linking microfrontend app
- HOST:
webpack.config.js
> plugins > exposes > add module in following syntax:
exposes: { APP_NAME: "APP_NAME@http://HOST_URL:PORT/remoteEntry.js" }
- REMOTE:
webpack.config.js
> plugins > remotes > add module in following syntax:
remotes: { HOST_APP_NAME: "HOST_APP_NAME@http://HOST_URL:PORT/remoteEntry.js" }
- HOST:
-
Shared library / Shared definitons
- Creating shared module
npx create-mf-app
> NAME_OF_LIB > Library > ...npm i react react-dom
&&npm i @types/react @types/react-dom -D
- Define type and export the type of target component
npm run build
npm link
in lib directory (allows linking for host and remote)- cd into HOST_DIR and
npm link SHARED_LIB_NAME
, i.e.cd home && npm link shared
- cd into REMOTE_DIR and
npm link SHARED_LIB_NAME
, i.e.cd login && npm link shared
- add type support into REMOTE by:
@types/REMOTE_NAME/COMPONENT_NAME/index.d.ts
and add
import React from "react"; import type { COMPONENT_TYPE } from "shared"; const COMPONENT_NAME: COMPONENT_TYPE; export default COMPONENT_NAME
- add typescript config into REMOTE by
tsc --init
- change tsconfig to be able to read jsx syntax by uncommenting
"jsx": "preserve"
and chaning the value to"jsx": "react"
- change tsconfig to be able to import type definitions by uncommenting
"paths": {}
and changing the value to
"paths": { "*": [ "src/@types/*" ] }
- import type from shared lib in code
import type { Home } from "shared"
- Creating shared module