RingCentral Micro Frontends is a micro frontends framework for building Web applications, and it's based on Module Federation of Webpack.
- @ringcentral/mfe-builder: Provides Webpack plugin for RC MFE builds
- @ringcentral/mfe-cli: A core MFE CLI for registry
- @ringcentral/mfe-core: A core MFE runtime
- @ringcentral/mfe-react: Provide React-based MFE runtime
- @ringcentral/mfe-shared: Shared collection at runtime and build-time
- @ringcentral/mfe-transport: Provide a global communication transport for MFE
- @ringcentral/mfe-service-worker: Provide a service-worker for MFE
- @ringcentral/mfe-sentry: Provide a global sentry for MFE
- @ringcentral/mfe-logger: Provide a global logger for MFE
- Dependencies management - Set
site.config.jsonorsite.config.js - Compatible with building local-only SPA - Use
yarn build --env spa - Multiple types of rendering containers - Support Micro-App/iframe/WebComponent
- MFE Lifecycle - Provide
init,mountandunmountAPIs as lifecycles - Generic Communication - Use
@ringcentral/mfe-transportas a global communication transport for MFE - CSS isolation - Support CSS modules CSS isolation injection for Webpack
style-loaderand so on. - Debugger/Logger - Provide meta info for Debugging/Logging.
- Version control - Support custom registry for MFE remote entry version control
yarn add @ringcentral/mfe-builder -D
yarn add @ringcentral/mfe-reactOr use npm
npm install -D @ringcentral/mfe-builder
npm install @ringcentral/mfe-react- Set
site.config.jsorsite.config.jsonin the root path.
/** @type {import('@ringcentral/mfe-builder').SiteConfigFile} */
module.exports = () => {
return {
name: '@example/app1',
dependencies: {
'@example/app2': 'http://localhost:3002/remoteEntry.js',
},
exposes: {
'./src/bootstrap': './src/bootstrap',
},
shared: {
react: { singleton: true },
'react-dom': { singleton: true },
},
};
};And use ModuleFederationPlugin for Webpack config from @ringcentral/mfe-builder.
const { ModuleFederationPlugin } = require('@ringcentral/mfe-builder');
module.exports = {
//...
plugins: [
new ModuleFederationPlugin(),
],
};- Define
app1andapp2exposed APIs in bootstrap files.
import { expose } from '@ringcentral/mfe-react';
export default expose({
init: () => {
//
},
render: (element = document.getElementById('root')) => {
ReactDOM.render(<App />, element);
return () => {
ReactDOM.unmountComponentAtNode(element!);
};
},
});- Consume
app2MFE inapp1.
import { useApp } from '@ringcentral/mfe-react';
const App2 = useApp({
name: '@example/app2',
loader: () => import('@example/app2/src/bootstrap'),
});- You can bootstrap
app1andapp2projects with RC MFE.
- Use SharedWorker in host application with
getWorkerName - Dynamically import bootstrap file in worker thread
- Add another entry points with
target: 'webworker'and setoutput.publicPathandoutput.pathin MFE webpack config(e.g.examples/basic/app3/webpack.config.js).
webpack dev serveris not supported in multiple entry points, so you need to build and serve the worker file manually(e.g.examples/basic/app3/dev.js). After building, all files in theworkerdirectory except forremoteEntry.jsdo not need to be deployed.This means that you will have two MFE bundled files in different directories, e.g.http://localhost:3000/remoteEntry.jsandhttp://localhost:3000/worker/remoteEntry.js. The name of theworkerdirectory config is hardcode here.
Note:
packages/builder/src/make.tsandpackages/shared/src/*Make sure that any variables of the function are serializable and passed in externally, and disable async await syntax, otherwise it will throw error in MFE runtime.
- Clone the repo
git clone https://github.com/ringcentral/ringcentral-mfe.git- bootstrap the repo
cd mfe
yarn install- Install and bootstrap the basic example
cd examples/basic
yarn install- Watch the sub-project
@ringcentral/mfe-builderand@ringcentral/mfe-shared.
cd ../..
yarn watch- Start the basic example.
yarn start- Run testing
- Write and watch unit testing
yarn test- Write and run E2E testing with
playwright
yarn e2e:test- Write and run integration testing
yarn it:test- Submit commit with
commitizen
yarn commit- Run all tests in CI.
yarn ci:test-
Submit PR and wait for the CI to pass.
-
Merge PR after the review.
This repo publishes packages through GitHub Actions when a GitHub Release is published.
- Update package versions.
# stable release (example: 0.4.19)
yarn update:version patch
# first beta release (example: 0.4.19-beta.0)
yarn update:version prepatch --preid beta
# next beta release (example: 0.4.19-beta.1)
yarn update:version prerelease --preid beta- Submit PR and wait for CI to pass.
- Merge PR after review.
- Create a release in GitHub:
- Stable release:
- Tag format:
vX.Y.Z(for examplev0.4.19) - Do not mark as pre-release
- Published to npm dist-tag
latest
- Tag format:
- Beta release:
- Tag format:
vX.Y.Z-beta.N(for examplev0.4.19-beta.0) - Mark as
This is a pre-release - Published to npm dist-tag
beta
- Tag format:
- Stable release:
Safety check: if a GitHub pre-release tag does not contain
-beta., the publish workflow will fail intentionally.
RingCentral Micro Frontends is MIT licensed.