Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A progressive micro frontends framework for building Web applications

License

NotificationsYou must be signed in to change notification settings

unadlib/fronts

Repository files navigation

Fronts Logo


Node CInpm versionlicense

Fronts is a progressive micro frontends framework for building Web applications, and it's based on themodule federation of Webpack.

Motivation

Among the many micro frontends solutions,single-spa andModule Federation are the best of them.

single-spa is a micro frontends framework based on router configuration. The centralization of configuration brings some limitations, such as it is difficult to granulate nestable micro frontends, module granularity control, module sharing, and so on.

In 2019, Zack Jackson proposed and implemented Module Federation. Module Federation is a completely different concept from single-spa, and allows a JavaScript application to dynamically load code from another application. It completely solves the problem of code dependency sharing and runtime modularity. The idea is true -A game-changer in JavaScript architecture as mentioned in Zack Jackson's article. And it's currently supported by Webpack, Next.js, and Rollup.

Although the Module Federation concept is so amazing, it has not yet gone further to provide a more complete and fully targeted micro frontends framework implementation, and this is what Fronts is trying to do.

Features

  • Non-module-federation - Although Fronts is based on the concept of module federation, it also supportsnon-module-federation mode.
  • Decentralized configuration - Configuresite.json for dependency management in each Fronts app, support for nested micro frontends.
  • Cross frameworks - No framework or technology stack is restricted.
  • Code splitting & lazy loading - Support code splitting within the Fronts app as a module, it can be lazy loaded by other Fronts app as a dependent module.
  • CSS isolation - Optional CSS isolation solution.
  • Lifecycle - Fronts provide concise lifecycle for Fronts app entry.
  • Web Components & iFrame - Support for multiple frontend containers.
  • Multiple patterns - Support for buildingmicro-frontends app andnon-micro-frontends app.
  • Monorepo & TypeScript - Friendly support for Monorepo and TypeScript, which are mutually appropriate technology stack.
  • Version control - It's used for efficient and dynamic delivery apps such as canary release.
  • Zero hijacking - Fronts didn't do any hijacking, maintaining originality and possible loss of performance and security.
  • Generic Communication - Fronts provides concise and generic communication APIs, which supports almost all frontend environments.

Getting Started

You can follow this article(React without create-react-app Webpack 5) to quickly createapp1 andapp2 React projects.

Assuming you've completed these steps, let's get started with a quick taste of the wonderful micro frontends development of Fronts.

  1. Installfronts-react andfronts-bundler in the projects.
# with NPMnpm install fronts-react fronts-bundler# or with Yarnyarn add fronts-react fronts-bundler
  1. Set upsite.json andwebpack.config.js in the projects

We defineapp1 as a parent micro frontend and it depends onapp2.

app1/site.json:

{"name":"app1","exports": [],"dependencies": {"app2":"http://localhost:3002/remoteEntry.js"  }}

app2 doesn't have any dependencies, it acts as a micro frontend and we define it to export./src/bootstrap as a micro frontends entry, this entry ofapp2 end will be used byapp1.

app2/site.json:

{"name":"app2","exports": ["./src/bootstrap"],"dependencies": {}}

Wrap the Webpack config withcreateWebpackConfig() inconfig/webpack.config.js in the projects.

const{ createWebpackConfig}=require('fronts-bundler');module.exports=createWebpackConfig(originalWebpackConfig);
  1. Define the default exported bootstrap function inapp2/src/bootstrap.jsx and useboot() to get it booted.
importReactfrom'react';importReactDOMfrom'react-dom';import{boot}from'fronts-react';importAppfrom'./App';exportdefaultfunctionrender(element){ReactDOM.render(<App/>,element);return()=>{ReactDOM.unmountComponentAtNode(element);};}boot(render,document.getElementById('root'));
  1. Loadapp1/src/App.jsx withuseApp() to importapp2.
importReactfrom'react';import{useApp}from'fronts-react';exportconstApp=()=>{constApp2=useApp({name:'app2',loader:()=>import('app2/src/bootstrap'),});return<App2/>;};

Examples

APIs

APIIsolation
useApp()CSS(loose/optional)
useWebComponents()CSS
useIframe()CSS, JavaScript

Built-in packages

The most popular frontend frameworks are React, Vue and Angular. When the micro frontends uses one of these frameworks, it is recommended to use Fronts built-in package for this framework, such asfronts-react,fronts-vue andfronts-ng, otherwise please usefronts.

PackagesSupport FrameworkStatus
frontsAny FrameworkCompleted ✅
fronts-reactReactCompleted ✅
fronts-vueVueIn Progress 💡
fronts-viteVueIn Progress 💡
fronts-ngAngular-

Running Type

TypeRequirementSupport
Non-Module-Federation-Dependency Management ❌
Monorepo ❌
Version Management ❌
Module FederationWebpack
site.json
Dependency Management ✅
Monorepo ✅
Version Management ❌
Version ControlWebpack
site.json
Registry Server
Dependency Management ✅
Monorepo ✅
Version Management ✅

Debugger/Logger

UsegetMeta(), it helps you to get the dependency mapping information.

import{getMeta}from'fronts';console.log(getMeta());// {//   "name": "app3",//   "meta": {//       "__main__": "app1",//       "__entry__": "http://localhost:3001/#/app2",//       "app2": {//           "dependencies": {//               "app3": "http://localhost:3003"//           }//       },//       "app5": {//           "dependencies": {//               "app6": "http://localhost:3006"//           }//       },//       "app3": {//           "dependencies": {}//       },//       "app6": {//           "dependencies": {}//       },//       "app1": {//           "dependencies": {//               "app2": "http://localhost:3002",//               "app4": "http://localhost:3004",//               "app5": "http://localhost:3005"//           }//       }//   }// }

Testing

fronts-test provides an runner for function step, and any micro frontends IT and E2E can use it for reusable testing. It also provides other APIs, such asuseContext(), beforeHook and afterHook increateRunner().

import{$,useContext,run,When,Then}from'fronts-test';constaddTodo=()=>{const{ page}=useContext();awaitpage.type('.text','Use Fronts');awaitpage.click('.add');};test('base',async()=>{awaitrun(Given('user open the page',entry),When('user add todo text',addTodo),Then('user should see that todo list has a new item',checkTodo));});

CLI

todo

Version Control

Set up the registry server URL in theregistry field.

It supports dynamicimport(), and it does not support static import.

{  "name": "app1",  "exports": [],+ "registry": "http://localhost:3000/dev.json",  "dependencies": {-    "app2": "http://localhost:3002/remoteEntry.js"+    "app2": "1.0.0"  }}

Start the registry server and make sure thathttp://localhost:3000/dev.json?scope=app2%401.0.0 request gets a response data with the version specification.

{"app2":"http://localhost:3002/remoteEntry.js"}

Tutorial

todo

Q&A

Q: Can Non-Module-Federation, Module Federation, and Version Control be compatible with each other?

A: Yes

Q: How to use SPA development mode in micro frontends codebase?

A: UseSPA=true yarn start instead ofyarn start, make sure the current codebase is Monorepo and module federation or version control is enabled, and it just works withuseApp() anduseWebComponent().

License

Fronts is MIT licensed.

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp