WO2022135178A1 - 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 - Google Patents

微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 Download PDF

Info

Publication number
WO2022135178A1
WO2022135178A1 PCT/CN2021/137072 CN2021137072W WO2022135178A1 WO 2022135178 A1 WO2022135178 A1 WO 2022135178A1 CN 2021137072 W CN2021137072 W CN 2021137072W WO 2022135178 A1 WO2022135178 A1 WO 2022135178A1
Authority
WO
WIPO (PCT)
Prior art keywords
application
sub
micro
resource
routing
Prior art date
Application number
PCT/CN2021/137072
Other languages
English (en)
French (fr)
Inventor
陈思名
罗亮之
陈江松
蒋鹏
Original Assignee
腾讯科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 腾讯科技(深圳)有限公司 filed Critical 腾讯科技(深圳)有限公司
Priority to KR1020237010638A priority Critical patent/KR20230054474A/ko
Priority to JP2023515655A priority patent/JP7451825B2/ja
Publication of WO2022135178A1 publication Critical patent/WO2022135178A1/zh
Priority to US17/962,218 priority patent/US20230036980A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
    • G06F16/9566URL specific, e.g. using aliases, detecting broken or misspelled links
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/451Execution arrangements for user interfaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45504Abstract machines for programme code execution, e.g. Java virtual machine [JVM], interpreters, emulators
    • G06F9/45529Embedded in an application, e.g. JavaScript in a Web browser
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • G06F9/505Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals considering the load
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/541Interprogram communication via adapters, e.g. between incompatible applications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/545Gui

Definitions

  • the embodiments of the present application relate to the field of Internet technologies, and relate to, but are not limited to, a micro front-end system, a sub-application loading method, an electronic device, a computer program product, and a computer-readable storage medium.
  • micro-frontends came into being.
  • the micro front-end draws on the concept of back-end micro-services, and splits a huge front-end project into small projects. These small projects are fully capable of independent development and operation. The whole system is coordinated by these small projects to realize the display and interaction of all pages.
  • the micro-front-end framework routing service of related technologies uses Nginx service forwarding, which is inefficient.
  • the central routing depends on the stability of the Nginx service, and the disaster recovery solution is complex. high.
  • the embodiments of the present application provide a micro-front-end system, a sub-application loading method, an electronic device, a computer program product, and a computer-readable storage medium, which can improve capacity expansion and disaster tolerance through a node service that can maintain and operate independently, and provide Ability to run sub-applications under multiple frameworks.
  • micro front-end system including:
  • the routing registration service is a Node back-end service that maintains and operates independently, and is configured to provide the routing information of the sub-application, the loading method of the sub-application and the deployment information of the sub-application for the micro-front-end running framework of the main application;
  • the command line tool is configured to provide a new sub-application function, an access sub-application function, and a service registration function through the command line;
  • the micro-frontend running framework is a framework running on the main application, configured to load and run the sub-applications based on the acquired network request, and provide the sub-application running capability under multiple frameworks.
  • the embodiment of the present application provides a sub-application loading method, the method is executed by an electronic device, and should be configured as a micro-front-end system, and the micro-front-end system includes: a routing registration service, a sub-application loading module, and a sub-application running module.
  • the method include:
  • URL Uniform Resource Locator
  • the sub-application loading module acquires the sub-application resource corresponding to the routing information from the routing registration service based on the routing information;
  • the sub-application loading module loads the sub-application resource
  • the sub-application running module runs the sub-application resource, and renders the page of the sub-application.
  • Embodiments of the present application provide a computer-readable storage medium, which stores executable instructions and is configured to implement the foregoing method for loading sub-applications based on a micro-front-end system when executed by a processor.
  • An embodiment of the present application provides an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to execute the above-mentioned method for loading sub-applications based on a micro-front-end system through the computer program.
  • Embodiments of the present application provide a computer program product, including a computer program, which implements the above-mentioned method for loading sub-applications based on a micro-front-end system when the computer program is executed by a processor.
  • the micro-front-end system provided in the embodiment of this application includes a routing registration service, a command-line tool, and a micro-front-end operating framework, and maintains and operates the Node back-end service independently, so that it can provide good capacity expansion and disaster tolerance.
  • the micro-front-end running framework of the main application provides routing information, loading methods and deployment information of sub-applications; provides new sub-applications, access sub-applications, and service registration functions through command-line tools; provides sub-applications under multiple frameworks operational capability.
  • FIG. 1 is a schematic diagram of the composition and structure of a micro-front-end system provided by an embodiment of the present application
  • FIG. 2 is a schematic diagram of another composition structure of a micro-front-end system provided by an embodiment of the present application.
  • FIG. 3 is a schematic flowchart of the implementation of the method for loading sub-applications based on a micro-front-end system provided by an embodiment of the present application;
  • FIG. 4 is a schematic flowchart of another implementation of a method for loading sub-applications based on a micro-front-end system provided by an embodiment of the present application;
  • FIG. 5 is a schematic flowchart of the implementation of the sub-application loading method based on the micro front-end system provided by the embodiment of the present application;
  • FIG. 6 is a schematic diagram of a micro-front-end system architecture provided by an embodiment of the present application.
  • FIG. 7 is a schematic diagram of a communication mechanism in a micro-front-end system provided by an embodiment of the present application.
  • FIG. 8 is a schematic flowchart of the implementation of the sub-application loading module for loading sub-application resources according to an embodiment of the present application
  • FIG. 9 is a schematic design diagram of a JS sandbox provided by an embodiment of the present application.
  • FIG. 10 is a schematic diagram of application layers provided by an embodiment of the present application.
  • Vue framework It is a set of progressive front-end frameworks for building user interfaces. The core library of Vue only focuses on the view layer.
  • React framework It is a JavaScript (JS) library configured to build a user interface. It is mainly configured to build a user interface. React can pass various types of parameters, such as declaring code, rendering the user interface, or static elements, or Dynamic variables and even interactive application components can be passed.
  • JS JavaScript
  • JavaScript sandbox mechanism It is a security mechanism that provides an isolated environment for running programs. It runs JS code by providing an execution environment that is isolated from the outside world. It is often used in micro-frontends to help independent online code that does not interfere with each other. , decoupling and reducing maintenance costs.
  • Web Worker It is a JavaScript multi-threaded solution provided by HyperText Markup Language (HTML, HyperText Markup Language) 5, which can hand over some computationally intensive code to the Web Worker to run without freezing the user interface. It is independent of other scripts and does not affect the performance of the page.
  • HTML HyperText Markup Language
  • Shadow Dom Shadow Document Object Model
  • HTML Tags Cascading Style Sheets
  • CSS Cascading Style Sheets
  • JavaScript code JavaScript code
  • Props transmission The template of the parent component contains child components.
  • the parent component must forward data or parameters to the child component. After the child component receives it, it renders different content or performs operations according to the parameters. This forward The process of passing data is achieved through Props.
  • Custom Event transmission The interaction between JavaScript and HTML is achieved through events. Events are some specific interaction moments that occur in the document or browser window. JavaScript can trigger specific automatic events at any time. Define events, and these events are the same as those created by the browser.
  • Sending messages PostMessage It is an application program interface method introduced by HTML5. It supports scripts from different sources to communicate effectively in an asynchronous manner. It can realize cross-text document, multi-window and cross-domain message delivery, and is configured for inter-window data communication. This also makes it an efficient solution for cross-domain communication.
  • Iframe is a hypertext markup language tag configured to create an inline frame (ie, inline frame) containing another document.
  • Node.js It is a JavaScript runtime environment based on the Chrome V8 engine. It uses an event-driven, non-blocking I/O model to allow JavaScript to run on the server-side development platform. It makes JavaScript a development platform that is compatible with PHP, Python, Perl , Ruby and other server-side languages are on an equal footing with scripting languages.
  • Polyfilling Indicates that a method already exists in the JavaScript specification, but a specific JavaScript engine does not yet support the method, so it can be implemented manually and used to fill the built-in prototype.
  • Single-SPA It is a set of micro-front-end framework, which takes over browser address switching to achieve the purpose of switching applications, and also manages the life cycle of each application from startup to destruction, and additional functions can be added during the change of the life cycle. (eg animation), and Single-SPA also provides plugins for different SPA frameworks to integrate existing applications.
  • Micro front-end including the main application and sub-applications, is a slice that divides the application into multiple vertical parts, and each slice is built from the underlying database to the upper user interface.
  • the main application is a framework, which mainly integrates login, menu, navigation, and provides global data and public methods, while specific functional modules are implemented in sub-applications as much as possible.
  • the functions of the main application may include: login, menu and navigation; the functions of the sub-application may correspond to specific page content.
  • FIG. 10 is a schematic diagram of application layers provided by the embodiment of the present application.
  • the back-pipe system requires login authentication, and has a menu bar on the left and a personal information navigation bar above. , the middle part is the specific page content. Based on this feature, the back management system can be divided into two parts: the main application (login module + menu module + navigation module) and the sub-application (specific content page module).
  • the positioning of the main application is the main frame, which mainly integrates the login module, menu module, and navigation module, and provides global data and public methods.
  • the sub-application needs to consider additional independence. If it is in a micro-frontend environment, the sub-application is used as a whole application. Therefore, it will be closely related to the main application, but the sub-application itself should be relatively independent, and it can also run independently of the main application.
  • the sub-application can be integrated into the main application and run in a micro-frontend architecture. , and can also be run independently from the main application, for example, the main application is a web page search application, and the sub-application is an advertisement recommendation application, a hot search application, and the like.
  • the routing service uses Nginx service forwarding, which is inefficient.
  • the central routing relies on the stability of the Nginx service, and the disaster recovery solution is complex.
  • the cost is high and the communication mechanism is single, which will make it difficult to manage events after too many applications.
  • Iframe as the application loader lacks the ability to arrange and control sub-applications.
  • the micro-frontend solution of the related art does not consider the running ability of sub-applications under the multi-frontend framework, the activation ability of sub-applications under multi-level routing, and the ability of sub-applications to actively invoke activation through the main application; it does not provide cross-domain resources.
  • the solution does not solve the problem that the front-end calls resources across domains after the distributed deployment of resources, including but not limited to interface requests, private static resources, and content delivery networks (CDN, Content Delivery Network). ) static resources, Web Worker resources, etc.
  • CDN Content Delivery Network
  • the embodiments of the present application provide a micro-front-end system, which provides an application loader module configured to load front-end applications of different frameworks, such as Vue framework, React framework, etc.; implements a JavaScript sandbox mechanism to ensure JS environment isolation; the system also Provides cross-domain processing of sub-application Web Worker, and implements CSS isolation by packaging and injecting CSS prefixes in sub-applications, injecting CSS prefixes when sub-applications are running, and loading sub-applications in Shadow Dom mode.
  • Three parent-child application communication mechanisms provide a route registration service, provide centralized route discovery capabilities, and are compatible with running under the original Iframe.
  • FIG. 1 is a schematic diagram of the composition and structure of the micro-front-end system provided by the embodiment of the present application.
  • the micro-front-end system 100 includes: a route registration service 101 , command line tool 102 and micro-front-end running framework 103, wherein the routing registration service 101 is a Node back-end service that maintains and runs independently, and is configured to provide routing information of sub-applications and loading of sub-applications to the micro-front-end running framework of the main application mode and deployment information for sub-applications.
  • a route registration service as a Node service that can be maintained and operated independently, it provides good expansion and disaster recovery capabilities, and maintains the registration and loading routes of sub-applications of the micro-frontend.
  • the route registration service can be a server that provides a Hyper Text Transfer Protocol (HTTP, Hyper Text Transfer Protocol) service.
  • HTTP Hyper Text Transfer Protocol
  • it can be implemented by Node.js, and a set of record routes, delete routes, and queries can be implemented through the Koa framework.
  • the web server for routing, login authorization and other functions, and the database uses a relational database management system (such as MySQL).
  • the route registration service 101 can be a service that implements the same function by any server or language, such as Java Spring Cloud, C++ Server Kit, etc.
  • routing registration service is a Node back-end service that is maintained and operated independently
  • a load balancing service can also be placed in front of the routing registration service. After obtaining network requests, network requests can be distributed based on the load of each routing registration service. It can also provide good capacity expansion and disaster recovery capabilities when the load of multiple routing registration services is large.
  • the command line tool 102 is configured to provide a function of creating a sub-application, a function of accessing a sub-application, and a function of service registration through a command line.
  • a tool for a user to interact with a command line can be provided through Inquirer.js.
  • the command line tool can be a command-line interface (CLI, command-line interface) tool, and also It can be an npm library or a graphical user interface (GUI, Graphical User Interface) tool.
  • CLI command-line interface
  • GUI graphical user interface
  • the command line tool 102 can receive commands input by the user such as creating a sub-application and accessing a sub-application, and perform service registration based on the received commands.
  • the micro-frontend running framework 103 is a framework running on the main application, configured to load and run sub-applications based on the obtained network request, and can provide the sub-application running capability under multiple frameworks.
  • the main application is also an application that arbitrarily accesses the micro-frontend running framework.
  • the micro-frontend running framework can be based on Single-SPA to provide multi-framework sub-application loading capabilities.
  • the micro-front-end system includes a routing registration service, a command-line tool, and a micro-front-end running framework, wherein the routing registration service is a Node back-end service that is maintained and operated independently, which can provide good capacity expansion and disaster tolerance.
  • the routing registration service provides the routing information, loading method, and deployment information of the sub-application for the micro-front-end running framework of the main application;
  • the command line tool is configured to provide new sub-applications, access sub-applications, and service registration through the command line.
  • micro-frontend running framework which is the framework running on the main application, is configured to load and run sub-applications based on the obtained network requests, and can provide the ability to run sub-applications under multiple frameworks.
  • the micro-front-end system further includes: a front-end interface 104 corresponding to the routing registration service, obtains the sub-application registration information that needs to be set for sub-application registration through the front-end interface 104, and registers the sub-application The information is sent to the route registration service.
  • the sub-application registration information includes: a sub-application framework, a sub-application routing mode, and a sub-application loading mode.
  • the sub-application framework may include Vue, React, etc.
  • the sub-application routing mode may include hash mode, history mode, etc.
  • the sub-application loading mode may include: JS loading mode, CSS loading mode, HTML loading mode Wait.
  • the sub-application registration information may further include the service name, the sub-application local development environment address, the sub-application online environment address, and the like.
  • the route registration service 101 is configured to receive sub-application registration information, and register the sub-application based on the sub-application registration information.
  • the command line tool 102 is configured to receive a new sub-application command, and obtain routing information, resource information and sub-application template information of the sub-application.
  • the routing information of the sub-application may include: the sub-application resource address and the sub-application resource registration path, the resource information of the sub-application may include the sub-application resource name and the sub-application resource type, and the sub-application template information may include the template identifier. .
  • the command line tool 102 generates a sub-application template based on the sub-application template information, and sends a sub-application creation request to the route registration service 101, where the sub-application creation request carries routing information and resource information.
  • the route registration service 101 after receiving the sub-application creation request, creates a sub-application based on the routing information and resource information carried in the sub-application creation request.
  • the command-line tool 102 sends a sub-application creation request to the routing registration service
  • the command-line tool 102 sends a sub-application deployment request to the deployment server
  • the deployment server performs resource deployment based on the sub-application resource address in the deployment request .
  • the command line tool 102 is further configured to receive an access sub-application command, obtain routing information and resource information of the sub-application, and send a sub-application access request to the routing registration service 101, where the sub-application access request is It carries the routing information and resource information of the sub-application;
  • the routing registration service 101 is further configured to receive a sub-application access request, and perform sub-application registration based on the routing information and resource information of the sub-application.
  • the composition structure of the micro-frontend running framework 103 shown in FIG. 1 is shown in FIG. 2 and includes: a basic function library module 1031, a communication module 1032, a unified routing module 1033, a sub-application loading module 1034, and a sub-application running module 1035, of which:
  • the basic function library module 1031 is configured to provide public methods and public components, and inject the public methods and public components into the sub-application by means of global variables and functions for use by the sub-application.
  • the basic function library module may also provide common polyfilling for sub-applications to use.
  • the communication module 1032 is configured to support communication mechanisms of main application to sub-application, sub-application to sub-application and sub-application to main application.
  • the communication mechanism from the main application to the sub-application includes props transmission and custom event Custom Event transmission
  • the communication mechanism from the sub-application to the sub-application includes asynchronous PostMessage transmission of different source scripts
  • the communication between the sub-application and the main application Mechanisms include Custom Event transmission.
  • Props transmission can provide responsive two-way data transmission capabilities
  • Custom Event can define the distribution and registration of events based on components, avoiding the impact of irrelevant events after too many applications
  • PostMessage provides global event sending and receiving, which is used to implement broadcast-type message notification .
  • there are corresponding implementation solutions in each communication dimension the means are abundant, and the side effects are small.
  • This embodiment of the application provides three types of communication support, including Props transmission, Custom Event transmission, and PostMessage transmission.
  • Props transmission can provide responsive two-way data transmission capability
  • Custom Event transmission can define event distribution and registration based on components, avoiding too many applications.
  • PostMessage transmission provides global event sending and receiving, and is configured to implement broadcast-type message notifications. There are responsive implementation schemes in each communication dimension, with rich means and small side effects.
  • the unified routing module 1033 is configured to monitor browser routing changes.
  • the unified routing module 1033 uses Single-SPA to monitor browser routing changes, load, activate, and run sub-applications or main application sub-paths under the specified framework.
  • the unified routing module is pulled from the routing registration service. Sub-application registration path, resources and other information under 1033.
  • the sub-application loading module 1034 is configured to acquire and load the resource corresponding to the sub-application resource address based on the sub-application resource address obtained from the routing registration service.
  • the sub-application loading module 1034 when the sub-application loading module 1034 loads the resource corresponding to the sub-application resource address, it will load the sub-application resource according to the sub-application loading mode in the sub-application registration information, wherein the sub-application loading module loads the mode of the sub-application At least include HTML entity mode, JS entity mode and Iframe mode.
  • the loading mode is HTML entity mode
  • the HTML file is loaded.
  • the loading mode is JS entity mode
  • the JS file is loaded.
  • the loading mode is Iframe mode
  • the URL is directly embedded in the Iframe to open.
  • the sub-application loading module 1034 after acquiring the resource corresponding to the sub-application resource address, acquires the service code of the sub-application based on the resource, parses the acquired service code of the sub-application, and parses the The latter service code is transmitted to the sub-application running module 1035 .
  • the sub-application running module 1035 is configured to run the resource corresponding to the resource address of the sub-application to render the sub-application page.
  • the sub-application running module 1035 includes a running environment sandbox, obtains the parsed business code from the sub-application running module, and executes the parsed business code in the running environment sandbox.
  • the runtime environment sandbox includes: JS sandbox, CSS sandbox, and Web Worker sandbox.
  • JS sandbox Use with statement and proxy to implement basic JS sandbox, achieve basic security under controllable sub-applications, and overcome scope escape methods through stack checking and keyword checking.
  • the proxy is a collection of objects accessible to the sub-application
  • the JS sandbox enables the business code of the sub-application to access only the objects accessible in the proxy, but not the objects of other sub-applications or the main application.
  • the parsed business code When the parsed business code is executed in the JS sandbox, the parsed business code is put into the sandbox with the proxy as the global root object for execution, that is to say, the business code can only access the objects and properties of the proxy without affecting the To other variables in the outer layer, to achieve safe isolation.
  • Three CSS sandbox methods are provided in the embodiments of the present application: one is based on the sub-application webpack packaging prefix, and the sub-application webpack packaging prefix is to assign a separate namespace to the styles of each sub-application, so as to avoid styles affecting each other; Based on the runtime prefix of the sub-application, dynamically add a prefix to the style of the sub-application when the sub-application is running to avoid style conflicts; the third is based on Shadow Dom, and the CSS sandbox based on Shadow Dom can provide browser-level style isolation capabilities. Complete isolation is possible.
  • the Web Worker sandbox is configured to run the script files assigned to the Web Worker inline to implement cross-domain calls of the Web Worker.
  • the sub-application resource loading module hijacks the *.worker.js file when loading resources, loads the file back into the browser memory as text content, and uses the Web Worker sandbox to run the Web Worker script file (*.worker.js inline) ), the inline running Web Worker script file will not cause cross-domain problems, thus solving the cross-domain problem of Web Worker.
  • the micro-frontend system further includes a server that supports cross-domain resource sharing.
  • the server automatically carries the Cross-origin Resource Sharing (CORS, Cross-origin Resource Sharing) header, so that it can support cross-origin resource sharing, allowing browsers to access private static resources and CD N static resources across domains.
  • CORS Cross-origin Resource Sharing
  • the embodiment of this application provides a server-side CORS solution including interface resources to support cross-domain, CDN static resources provide a CORS solution, and Web Worker provides an inline build loader and an inline run loader to solve the problem of calling workers across domains.
  • the embodiments of the present application also provide means such as caching, preloading, and Web Worker to accelerate the loading and invocation of sub-applications.
  • the micro-frontend running framework 103 further includes: a data management module 1036, a performance monitoring module 1037 and an error handling module 1038, wherein:
  • the data management module 1036 is configured to implement the data two-way binding function through the data provided by the Props transmission mechanism, so as to share the data of the parent and child applications.
  • the main application when the parent and child applications are loaded in the same operating environment, the main application will pass an object with a monitoring function to the child application, and the change of the child application can be monitored by the object, so that the parent-child application can be realized. sharing of data.
  • the performance monitoring module 1037 is configured to monitor the loading duration and running duration of the sub-application.
  • the main application monitors information such as the loading time and running time of the sub-applications through preset functions.
  • the error handling module 1038 is configured to monitor and process error information of the sub-application during the loading and running process.
  • the main application monitors and handles sub-application errors by registering window.addEventListener('error', errorHandler) and window.addEventListener('unhandledrejection', errorHandler), so that the error information of the sub-application can be processed in time to ensure the micro-frontend. system reliability.
  • this embodiment of the present application further provides a method for loading sub-applications based on the micro-front-end system, which should be configured as the micro-front-end system provided by the foregoing embodiments.
  • Step S301 acquiring a network access request.
  • the network access request carries a URL address.
  • the network access request may be triggered by a user's network access operation.
  • the functional network access request may be a request configured to access the main application, or may be a request to access a sub-application.
  • the network access request is a network access request for accessing a sub-application, it may be that the user enters the URL address of the main application in the browser, and after the browser renders the main application interface, the user can use the sub-application provided in the main application interface. icon to trigger a network access request to the child application.
  • the micro front-end system before step S301, has completed the deployment of the main application and the routing registration service, and has completed the creation and registration of the sub-application through the CLI tool.
  • step S302 corresponding routing information is pulled from the routing registration service of the micro front-end system based on the URL address.
  • the URL address may be sent to the routing registration service, and the routing registration service determines the application identifier to be accessed according to the URL address, and then pulls the corresponding routing information based on the application identifier.
  • Step S303 when it is determined based on the routing information that the page to be accessed is a sub-application page, the sub-application loading module of the micro front-end system obtains the sub-application resource corresponding to the routing information from the routing registration service based on the routing information.
  • the routing registration service can obtain the corresponding sub-application resources according to the routing information, such as CSS, JS and other static resources. document.
  • Step S304 when the sub-application resource needs to be loaded, the sub-application loading module loads the sub-application resource.
  • the sub-application loading module after acquiring the sub-application resource, the sub-application loading module first determines whether the sub-application resource needs to be loaded, and then loads the sub-application resource based on the sub-application loading mode when the sub-application resource needs to be loaded. When it is determined that the sub-application resource does not need to be loaded, it indicates that the sub-application resource has been loaded, and the sub-application resource is directly run to render the sub-application page.
  • Step S305 the sub-application running module of the micro front-end system runs the sub-application resources to render the page of the sub-application.
  • the sub-application loading module acquires the service code of the sub-application based on the sub-application resource, parses the acquired service code of the sub-application, and stores the parsed service code Transfer to the sub-application running module.
  • the sub-application running module obtains the parsed business code, and executes the parsed business code in the sandbox of its own running environment to render the page of the sub-application.
  • the runtime environment sandbox includes: JS sandbox, CSS sandbox, and Web Worker sandbox.
  • JS sandbox use the with statement and proxy to implement the basic JS sandbox, achieve basic security under the control of sub-applications, and overcome the scope escape method through stack checking and keyword checking.
  • the proxy is a collection of objects accessible to the sub-application
  • the JS sandbox enables the business code of the sub-application to only access the objects accessible in the proxy, and cannot access the objects of other sub-applications or the main application.
  • the parsed business code When the parsed business code is executed in the JS sandbox, the parsed business code is put into the sandbox with the proxy as the global root object for execution, that is to say, the business code can only access the objects and properties of the proxy without affecting the To other variables in the outer layer, to achieve safe isolation.
  • Three CSS sandbox methods are provided in the embodiments of the present application: one is based on the sub-application webpack packaging prefix, and the sub-application webpack packaging prefix is to assign a separate namespace to the styles of each sub-application, so as to avoid styles affecting each other; Based on the runtime prefix of the sub-application, the conflict of styles is avoided by dynamically loading and unloading the application style at the runtime of the sub-application; the third is based on Shadow Dom, and the CSS sandbox based on Shadow Dom can provide browser-level style isolation capabilities, which can be completely isolation.
  • the Web Worker sandbox is configured to run the script files assigned to the Web Worker inline to implement cross-domain calls of the Web Worker.
  • the sub-application resource loading module hijacks the *.worker.js file when loading resources, loads the file back into the browser memory as text content, and uses the Web Worker sandbox to run the Web Worker script file (*.worker.js inline) ), the inline running Web Worker script file will not cause cross-domain problems, thus solving the cross-domain problem of Web Worker.
  • the sub-application loading module of the micro-front-end system obtains the sub-application resource corresponding to the routing information from the routing registration service based on the routing information, and when the sub-application resource needs to be loaded, the sub-application The loading module loads the sub-application resources, and then the sub-application running module of the micro front-end system runs the sub-application resources to render the page of the sub-application.
  • the sub-application loading method based on the micro front-end system further includes:
  • Step S003 it is determined whether the sub-application resource is preloaded or whether it is opened.
  • step S304 when the sub-application resource has not been preloaded and has not been opened, it is determined that the sub-application resource needs to be loaded, and step S304 is entered at this time; when the sub-application resource has been preloaded or opened, it is determined that the sub-application resource is not It needs to be loaded again, in this case, go to step S305. This can speed up the loading and invocation of sub-applications.
  • the sub-application needs to be registered and deployed, and the sub-application registration process can be implemented through the following steps:
  • Step S001 acquiring sub-application registration information that needs to be set for sub-application registration, and sending the sub-application registration information to a routing registration service.
  • the sub-application registration information includes at least: a sub-application framework, a sub-application routing mode, and a sub-application loading mode.
  • the micro-front-end system may include a front-end interface corresponding to the routing registration service, and may also include command-line tools configured to create new sub-applications and access sub-applications.
  • step S001 when step S001 is implemented, there are two implementation modes:
  • the front-end interface When obtaining the sub-application registration information based on the first method, the front-end interface is first presented based on the operation instruction for opening the front-end interface, and then an input operation for sub-application registration is received through the front-end interface, and the input operation is inputting the sub-application registration.
  • Parameters that need to be set can include: service name, sub-application framework, sub-application local development environment address, sub-application online environment address, sub-application registration sub-route, sub-application routing mode (hash or history), sub-application loading mode Wait.
  • the front-end interface is further provided with a graphic control for determining registration. After the user determines to complete the setting of the registration information of the sub-application, the user can click or touch the graphic control to send the registration information of the sub-application to the routing registration. Serve.
  • the sub-application registration information is sent to the routing registration service, an HTTP request for sub-application registration may be sent to the routing registration service, and the HTTP request may carry the sub-application registration information.
  • the command-line tool when obtaining the registration information of the sub-application based on the command-line tool, the command-line tool must be started first, and then the command-line tool is used to receive the new sub-application command, and then the input operation for the newly-created sub-application is obtained.
  • the input operation is to input the parameters that need to be set for the registration of the sub-application, and then obtain the registration information of the sub-application according to the input operation.
  • a command to send information may be input, and the sub-application registration information is sent to the route registration service based on the command to send information.
  • Step S002 the routing registration service receives the sub-application registration information, and registers the sub-application based on the sub-application registration information.
  • the routing information and resource information of the sub-applications can be registered by themselves, thereby improving the flexibility of registering the sub-applications.
  • step S304 shown in FIG. 3 when the sub-application resource needs to be loaded, the sub-application loads the resource and loads the sub-application resource" can be implemented by the following steps:
  • Step S3041 when the sub-application resource needs to be loaded, the frame identifier of the sub-application and the resource loading mode are acquired.
  • the frame identifier of the sub-application may include Vue, React, etc.
  • the resource loading mode may include: JS entity loading mode, CSS entity loading mode, Iframe loading mode, and the like.
  • Step S3042 according to the resource loading type, load the sub-application resource in the sub-application frame corresponding to the frame identifier.
  • the loading mode is HTML entity mode
  • the HTML file is loaded
  • the loading mode is JS entity mode
  • the JS file is loaded
  • the loading mode is Iframe mode
  • the URL is directly embedded in the Iframe to open.
  • step S302 the following steps may also be performed:
  • Step S201 determining whether the page to be accessed is the main application page based on the routing information.
  • step S202 when it is determined based on the routing information that the page to be accessed is the main application page, step S202 is performed; when it is determined based on the routing information that the page to be accessed is a sub-application page, step S303 is performed.
  • Step 202 Determine the sub-application currently mounted by the main application according to the life cycle.
  • Step S203 determining the target sub-application to be rendered from the currently mounted sub-applications.
  • step S203 may be to determine at least one target sub-application to be rendered from the currently mounted sub-applications according to a preset rule, for example, it may be to select one or more target sub-applications with the most access times from the currently mounted sub-applications to determine for the target sub-application.
  • Step S204 based on the exposed loading function and the target sub-application, simulate route switching, and acquire sub-application resources and main application resources of the target sub-application.
  • the main application resources are first obtained according to the routing information.
  • the loading function since the loading function is exposed, the loading function can be actively called by the main application.
  • route switching can be simulated, thereby triggering the sub-application loading module of the micro-frontend system to obtain the target sub-application.
  • the app's sub-app resources are first obtained according to the routing information.
  • Step S205 load and run the main application resource and the sub-application resource, so as to render the sub-application in the rendered page of the main application.
  • step S205 When step S205 is implemented, first load and run the main application resources to render the main application interface, and then run the sub-application resources, and also render the sub-application pages, so that the main application can actively render the sub-applications without relying on route registration. .
  • the currently mounted sub-application when the page to be accessed is the main application page, the currently mounted sub-application may be determined according to the life cycle of the main application, and the target sub-application may be determined based on the preset principle, And by calling the exposed loading function, simulating route switching, obtaining the sub-application resources of the target sub-application, and displaying the sub-application page in the rendered main application page, so as to realize the active rendering of the sub-application by the main application.
  • FIG. 6 is a schematic diagram of a micro-front-end system provided by an embodiment of the present application.
  • the micro-front-end system includes: a routing registration service 601 and a front-end page corresponding to the routing registration service, sub-application access and a generated CLI tool 602 .
  • the routing registration service 601 provides the micro-frontend running framework 603 with routing information of the sub-application, loading method, and deployment information of the sub-application.
  • a front-end interface can be provided for sub-application routing registration, through which parameters required for routing registration can be set.
  • the parameters to be set include but are not limited to: service name, sub-application framework, sub-application local development environment address, sub-application online environment address, sub-application registration sub-route, sub-application routing mode (hash or history), sub-application loading mode.
  • Route registration service 601 is a server that provides HTTP services, mainly implemented by Node.js. It implements a set of web servers that record routing, delete routing, query routing, login authorization and other functions through the Koa framework.
  • the database can use MySQL, or you can use other forms of databases.
  • the route registration service can be a Node backend service, through which the registration information of the sub-application is received, the application loader parses and discovers the sub-application through the Node back-end service, and determines how to load the sub-application through the information Resources. Multiple Node single services are started through PM2.
  • PM2 is a Node application process manager with load balancing function.
  • the routing registration service can also include a load balancing service, which is configured to provide disaster recovery, liveness and capacity expansion capabilities of services.
  • the CLI tool 602 provides functions including creating a sub-application, accessing a sub-application, service registration and deployment.
  • a set of command-line tools are provided through Inquirer.js, including functions such as creating new sub-applications, accessing sub-applications, service registration and deployment.
  • the user can first enter the new sub-application command on the command line, and fill in the sub-application resource name, sub-application resource address, sub-application resource type, and sub-application resource registration path, and select the sub-application template.
  • CLI The tool automatically generates corresponding templates and injects routing information, and automatically registers resource information to the routing registration service.
  • the user can enter the access sub-application command on the command line, and fill in the sub-application resource name, sub-application resource address, sub-application resource type, and sub-application resource registration path, and the CLI tool automatically finds the sub-application Enter the entry file, and add the life cycle functions required by the main application.
  • the CLI tool automatically registers the resource information with the route registration service.
  • the CLI tool When the service registration function is implemented, the CLI tool carries the new sub-application command, fills in the sub-application resource name, sub-application resource address, sub-application resource type, sub-application resource registration path and other parameters, and sends it to the routing registration service through an HTTP request.
  • the CLI tool When the deployment function is implemented, the CLI tool sends a deployment request to the route registration service through an HTTP request.
  • the micro-frontend running framework 603 is a framework that runs in the main application.
  • the main application can also be called a parent application or an application shell (APP shell).
  • the APP shell includes a public resource library, an application loader, and a resource loader (Single- SPA package) and the runtime environment sandbox.
  • the runtime environment sandbox includes js sandbox, web worker inline sandbox and CSS environment isolation sandbox.
  • the APP shell also supports running in Iframe mode.
  • the main application is any application that accesses the micro-frontend running framework.
  • the micro-frontend running framework includes a basic function library, a communication module, a data management module, a performance monitoring module, an error handling module, a unified routing module, a sub-application loading module, and a sub-application running module.
  • the basic function library provides common polyfills, public methods and components, which are injected into sub-applications through global variables and functions for use by sub-applications.
  • the communication module provides event communication through Custom Event, message communication through PostMessage, and system data communication through Props transmission in the life cycle.
  • FIG. 7 is a schematic diagram of a communication mechanism in a micro-front-end system provided by an embodiment of the present application.
  • the communication mode from the main application to the sub-application may include: two communication mechanisms: Props and Custom Event, and the sub-application to the main application
  • the communication modes may include: Custom Event (component) and Custom Event (window) two communication mechanisms
  • the communication modes between sub-applications include: PostMessage and Broadcast Channel (BroadcastChannel) two communication modes.
  • the data management module through the data provided by Props, can realize the two-way data binding function and share the data of the parent and child applications.
  • the performance monitoring module is configured to monitor the loading time, running time and other data of the sub-applications through the function of the main application.
  • the error handling module is configured to monitor and handle the error information during the loading and running of the sub-application.
  • the main application monitors and handles errors reported by the sub-application by registering listeners, where the registered listeners include window.addEventListener('error', errorHandler) and window.addEventListener('unhandledrejection', errorHandler).
  • the unified routing module uses Single-SPA to monitor browser routing changes, loads and activates the sub-application or main application sub-path under the specified framework, and pulls the sub-application registration under the unified routing module from the routing registration service when the main application is initialized. Information such as paths, resources, etc.
  • Sub-application loading module configured to load sub-application resources.
  • FIG. 8 is a schematic diagram of the implementation process of loading sub-application resources by a sub-application loading module provided by an embodiment of the present application. As shown in FIG. 8 , the process includes:
  • Step S801 based on the acquired network request, pull the route and static resources from the route registration service.
  • the network request carries a URL address.
  • the application identifier corresponding to the URL address may be determined from the route registration service based on the URL address, and the route registration service may then determine the corresponding routing information according to the application identifier. , and obtain static resources based on routing information.
  • Step S802 the resource loader loads sub-application resources.
  • the resource loader can load sub-applications of different frameworks, and can load HTML Entry, JS Entry mode and Iframe mode.
  • HTML mode loads static files through reference resources in HTML
  • js mode loads resources dynamically through js, and also provides traditional Load sub-apps in Iframe mode.
  • the resource loader may also provide means such as preloading, caching, and idle loading.
  • Step S803 after the resource loader loads the sub-application resource, perform resource information registration.
  • the resource loader loads the sub-application resources
  • the loaded sub-application resource information is registered in the memory.
  • the sub-application loading module includes a resource loader and a resource loader.
  • the resource loader is based on the Single-SPA encapsulation, which can provide the sub-application running capability under the multi-frontend framework.
  • the Single-SPA provides the function of route monitoring. When the route is switched, the framework code and business code of the corresponding sub-application will be loaded according to the life cycle, so as to realize the ability to run different frameworks and multi-level routing activation; and by exposing the loading function to simulate the route switching, the main application can actively call the activation ability.
  • the sub-application running module includes JS sandbox and CSS sandbox (non-traditional Iframe mode exists), and the sub-application running module is responsible for loading the js resources pulled back by the sub-application loading module.
  • the JS sandbox design is shown in Figure 9.
  • the with function 901 and the proxy 902 are used to implement the basic js sandbox.
  • the proxy proxy and snapshot proxy modes can be implemented, and the snapshot proxy mode is compatible with environments that do not support ES6Proxy.
  • the actual code 903 of the sub-application parsed by the resource loader of the application loader is put into the proxy sandbox for execution.
  • stack checking and keyword checking are used to prevent them, so as to achieve basic security under the control of sub-applications.
  • Sub-applications need to uniformly access packaging tools, and assign a separate namespace to the styles of each sub-application;
  • Shadow Dom needs to deal with shadow boundaries, event loss, access control (shadowRoot) and other issues.
  • the micro-frontend system provided by the embodiments of this application provides a route registration service, as a Node service that can be maintained and operated independently, provides good capacity expansion, disaster tolerance, and maintains the registration and loading routes of sub-applications of the micro-frontend; and based on Single -SPA provides the ability to run sub-applications under multiple frameworks. Based on a customized loading scheme, it provides the ability for the main application to actively render sub-applications, and does not necessarily need to rely on routing registration; in addition, three types of communication support are provided in the communication mechanism, including Props transfer, Custom Event, PostMessage, and Props transmission can provide responsive two-way data transmission capabilities. Custom Event can define the distribution and registration of events based on components, avoiding the impact of irrelevant events after too many applications.
  • PostMessage provides global event sending and receiving, configured to achieve Broadcast message notifications have response implementation schemes in each communication dimension, with rich means and small side effects;
  • the micro-front-end system provides server-side CORS solutions including interface resources to support cross-domain, private static resources, and CDN static resources.
  • the CORS solution supports cross-domain.
  • Web Worker provides inline build loader and inline runtime loader to solve the problem of calling workers across domains, and also provides caching, preloading, Web Worker and other means to accelerate the loading and invocation of sub-applications; and provides running The scheme of loading sub-applications at runtime can change the rendering content and interaction logic of sub-applications at runtime, providing higher freedom.
  • Embodiments of the present application provide a computer program product or computer program, where the computer program product or computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium.
  • the processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the micro-front-end system-based sub-application loading method described in the embodiments of the present application.
  • Embodiments of the present application provide a storage medium storing executable instructions, where executable instructions are stored, and when the executable instructions are executed by a processor, the processor will cause the processor to execute the sub-application loading method provided by the embodiments of the present application, for example , the sub-application loading method shown in FIG. 3 , FIG. 4 and FIG. 5 .
  • the storage medium may be a computer-readable storage medium, for example, Ferromagnetic Random Access Memory (FRAM), Read Only Memory (ROM), Programmable Read Only Memory (PROM). Read Only Memory), Erasable Programmable Read Only Memory (EPROM, Erasable Programmable Read Only Memory), Electrically Erasable Programmable Read Only Memory (EEPROM, Electrically Erasable Programmable Read Only Memory), Flash Memory, Magnetic Surface Memory, Optical Disc, Or memory such as CD-ROM (Compact Disk-Read Only Memory); it can also be various devices including one or any combination of the above memories.
  • FRAM Ferromagnetic Random Access Memory
  • ROM Read Only Memory
  • PROM Programmable Read Only Memory
  • EPROM Erasable Programmable Read Only Memory
  • EEPROM Electrically Erasable Programmable Read Only Memory
  • Flash Memory Magnetic Surface Memory
  • Optical Disc Or memory such as CD-ROM (Compact Disk-Read Only Memory); it can also be various devices including one or any combination of the above memories.
  • executable instructions may take the form of programs, software, software modules, scripts, or code, written in any form of programming language, including compiled or interpreted languages, or declarative or procedural languages, and which Deployment may be in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
  • executable instructions may, but do not necessarily correspond to files in a file system, may be stored as part of a file that holds other programs or data, for example, a Hyper Text Markup Language (HTML, Hyper Text Markup Language) document in one or more scripts, stored in a single file specifically configured for the program in question, or in multiple cooperating files (e.g., files that store one or more modules, subprograms, or portions of code) .
  • executable instructions may be deployed to be executed on one computing device, or on multiple computing devices located at one site, or alternatively, distributed across multiple sites and interconnected by a communication network execute on.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Multimedia (AREA)
  • Human Computer Interaction (AREA)
  • Information Transfer Between Computers (AREA)
  • Stored Programmes (AREA)

Abstract

本申请实施例提供一种微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质,该微前端系统包括:路由注册服务、命令行工具和微前端运行框架,其中,所述路由注册服务,为独立维护运行的节点Node后端服务,配置为为所述主应用的微前端运行框架提供子应用的路由信息、所述子应用的加载模式和所述子应用的部署信息;所述命令行工具,配置为通过命令行提供新建子应用功能、接入子应用功能、服务注册功能;所述微前端运行框架,为运行在主应用的框架,配置为基于获取到的网络请求加载并运行所述子应用,并提供多框架下的子应用运行能力。

Description

微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质
相关申请的交叉引用
本申请基于申请号为202011520184.6、申请日为2020年12月21日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。
技术领域
本申请实施例涉及互联网技术领域,涉及但不限于一种微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质。
背景技术
在进行前端开发的过程中,开发工程越来越庞大,并且产品功能复杂,代码冲突频繁,影响面巨大。针对这一系列的问题,微前端应运而生。微前端借鉴后端微服务的概念,将一个巨大的前端工程拆分成一个个的小工程,这些小工程完全具备独立开发、运行能力。整个系统由这些小工程协同合作,实现所有页面的展示与交互。
相关技术的微前端框架路由服务使用Nginx服务转发,效率低下,中心路由依靠Nginx服务的稳定性,容灾处理方案复杂,Nginx服务高度依赖Nginx服务配置,配置修改需要重启中心路由Nginx服务,维护成本高。
发明内容
本申请实施例提供一种微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质,通过可独立维护运行的节点(Node)服务,提升扩容以及容灾能力,并提供多框架下子应用运行能力。
本申请实施例的技术方案是这样实现的:
本申请实施例提供一种微前端系统,包括:
路由注册服务、命令行工具和微前端运行框架,其中,
所述路由注册服务,为独立维护运行的Node后端服务,配置为为主应用的微前端运行框架提供子应用的路由信息、所述子应用的加载方式和所述子应用的部署信息;
所述命令行工具,配置为通过命令行提供新建子应用功能、接入子应用功能、服务注册功能;
所述微前端运行框架,为运行在所述主应用的框架,配置为基于获取到的网络请求加载并运行所述子应用,并提供多框架下的子应用运行能力。
本申请实施例提供一种子应用加载方法,所述方法由电子设备执行,并应配置为微前端系统,所述微前端系统包括:路由注册服务、子应用加载模块和子应用运行模块,所述方法包括:
获取配置为访问子应用的网络访问请求,所述网络访问请求中携带有所述子应用的统一资源定位符(URL,Uniform Resource Locator)地址;
基于所述子应用的URL地址从所述路由注册服务拉取所述子应用对应的路由信息;
当基于所述路由信息确定所述待访问页面为子应用页面时,所述子应用加载模块基于所述路由信息,从所述路由注册服务获取所述路由信息对应的子应用资源;
当需要加载所述子应用资源时,所述子应用加载模块加载所述子应用资源;
所述子应用运行模块运行所述子应用资源,并渲染出子应用的页面。
本申请实施例提供一种计算机可读存储介质,存储有可执行指令,配置为被处理器执行时,实现上述的基于微前端系统的子应用加载方法。
本申请实施例提供一种电子设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行上述的基于微前端系统的子应用加载方法。
本申请实施例提供一种计算机程序产品,包括计算机程序,所述计算机程 序被处理器执行时实现上述的基于微前端系统的子应用加载方法。
本申请实施例具有以下有益效果:
在本申请实施例提供的微前端系统,包括路由注册服务、命令行工具和微前端运行框架,通过独立维护运行的Node后端服务,如此能够提供很好的扩容和容灾能力,通过路由注册服务为主应用的微前端运行框架提供子应用的路由信息、加载方式和子应用的部署信息;通过命令行工具提供新建子应用、接入子应用、服务注册功能;通过提供多框架下的子应用运行能力。
附图说明
图1为本申请实施例提供的微前端系统的组成结构示意图;
图2为本申请实施例提供的微前端系统的另一种组成结构示意图;
图3为本申请实施例提供的基于微前端系统的子应用加载方法的实现流程示意图;
图4为本申请实施例提供的基于微前端系统的子应用加载方法的另一种实现流程示意图;
图5为本申请实施例提供的基于微前端系统的子应用加载方法的实现流程示意图;
图6为本申请实施例提供的微前端系统架构示意图;
图7为本申请实施例提供的微前端系统中通信机制的示意图;
图8为本申请实施例提供的子应用加载模块加载子应用资源的实现流程示意图;
图9为本申请实施例提供的JS沙箱的设计示意图;
图10为本申请实施例提供的应用分层示意图。
具体实施方式
为了使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请作进一步地详细描述,所描述的实施例不应视为对本申请的限制,本领域普 通技术人员在没有做出创造性劳动前提下所获得的所有其它实施例,都属于本申请保护的范围。
在以下的描述中,涉及到“一些实施例”,其描述了所有可能实施例的子集,但是可以理解,“一些实施例”可以是所有可能实施例的相同子集或不同子集,并且可以在不冲突的情况下相互结合。除非另有定义,本申请实施例所使用的所有的技术和科学术语与属于本申请实施例的技术领域的技术人员通常理解的含义相同。本申请实施例所使用的术语只是为了描述本申请实施例的目的,不是旨在限制本申请。
除非另有定义,本文所使用的所有的技术和科学术语与属于本申请的技术领域的技术人员通常理解的含义相同。本文中所使用的术语只是为了描述本申请实施例的目的,不是旨在限制本申请。
对本申请实施例进行进一步详细说明之前,对本申请实施例中涉及的名词和术语进行说明,本申请实施例中涉及的名词和术语适配置为如下的解释。
1)Vue框架:是一套构建用户界面的渐进式前端框架,Vue的核心库只关注视图层。
2)React框架:是配置为构建用户界面的JavaScript(JS)库,主要配置为构建用户界面,React能够传递多种类型的参数,如声明代码,渲染出用户界面、也可以是静态元素、也可以传递动态变量、甚至是可交互的应用组件。
3)JavaScript沙盒机制:是一种安全机制,为运行中的程序提供隔离环境,通过提供一个与外界隔绝的执行环境来运行JS代码,在微前端中常用来帮助独立上线互不干扰的代码,解耦,减少维护成本。
4)Web Worker:是超文本标记语言(HTML,HyperText Markup Language)5提供的一个JavaScript多线程解决方案,可以将一些大计算量的代码交由Web Worker运行而不冻结用户界面。它独立于其他脚本,不会影响页面的性能。
5)影子文件对象模型(Shadow Dom,Shadow Document Object Model):是超文本标记语言的规范,它允许在文档渲染时插入一颗文档对象模型元素子树,它允许浏览器开发者封装自己的HTML标签、层叠样式表(CSS:Cascading  Style Sheets)样式和特定的JavaScript代码、同时开发人员也可以创建类似<input>、<video>、<audio>等这样的自定义的一级标签。
6)Props传输:父组件的模板中包含子组件,父组件要正向地向子组件传递数据或参数,子组件收到后根据参数的不同来渲染不同的内容,或者执行操作,这个正向传递数据的过程是通过Props来实现的。
7)自定义事件(Custom Event)传输:JavaScript与HTML之间的交互是通过事件来实现的,事件是文档或浏览器窗口发生的一些特定的交互瞬间,通过JavaScript可以在任何时刻触发特定的自定义事件,并且这些事件与浏览器创建的事件是相同的。
8)发送消息PostMessage:是HTML5引入的应用程序接口方法,支持来自不同源的脚本采用异步方式进行有效的通信,可以实现跨文本文档,多窗口跨域消息传递,多配置为窗口间数据通信,这也使它成为跨域通信的一种有效的解决方案。
9)Iframe:是超文本标记语言标签,配置为创建包含另外一个文档的内联框架(即行内框架)。
10)Node.js:是一个基于Chrome V8引擎的JavaScript运行环境,使用了一个事件驱动、非阻塞式I/O模型,让JavaScript运行在服务端的开发平台,它让JavaScript成为与PHP、Python、Perl、Ruby等服务端语言平起平坐的脚本语言。
11)Polyfilling:表示某个方法在JavaScript规范中已存在,但是特定的JavaScript引擎尚不支持该方法,那么可以通过手动实现它,并用以填充内建原型。
12)Single-SPA:是一套微前端框架,它接管浏览器地址切换以达到切换应用的目的,也管理着各个应用从启动到销毁的生命周期,在生命周期变化过程中可以添加额外的功能(例如动画),同时Single-SPA也为不同的SPA框架提供了插件,以整合现存的应用。
13)微前端:包括主应用和子应用,是将应用程序划分为多个垂直部分的 切片,每个切片都是从底层数据库到上层的用户界面构建的。主应用的是一个框架,主要是集成登录、菜单、导航,以及提供全局数据和公共方法,而具体的功能模块尽量在子应用中实现。例如,主应用的功能可以包括:登录、菜单和导航;子应用的功能可以对应具体的页面内容。
14)模块打包器(webpack):它用于分析项目结构,找到JavaScript模块以及浏览器不能直接运行的拓展语言,并将其转换和打包为合适的格式供浏览器使用。参见图10,图10本申请实施例提供的应用分层示意图,下面结合实际的后管系统为例进行说明,后管系统需要登录鉴权,有左侧的菜单栏和上方的个人信息导航栏,中间部分是具体的页面内容,基于这个特点,可以把后管系统分成主应用(登录模块+菜单模块+导航模块)和子应用(具体的内容页面模块)两个部分。主应用的定位是主体框架,主要集成登录模块、菜单模块、导航模块,并提供全局数据和公共方法,子应用需要额外考虑独立性,如果是在微前端的环境中,子应用是作为整体应用的一部分的,因此会与主应用有着紧密的联系,但是子应用本身也应该做到相对的独立,脱离了主应用也能单独运行,子应用既能集成在主应用中以微前端的架构运行,也能够脱离主应用单独运行,例如,主应用为网页搜索应用,子应用为广告推荐应用、热搜应用等等。
相关技术的微前端方案中路由服务使用Nginx服务转发,效率低下,中心路由依靠Nginx服务的稳定性,容灾处理方案复杂,Nginx方案高度依赖Nginx服务配置,配置修改需要重启中心路由Nginx服务,维护成本高,通信机制单一,会造成应用过多后事件难以管理,使用Iframe作为应用加载器,缺少对子应用的编排和控制能力。相关技术的微前端方案,没有考虑多前端框架下的子应用运行能力,没有考虑子应用在多级路由下的激活能力,没有考虑子应用通过主应用主动调用激活的能力;没有提供资源跨域解决方案,相关技术的微前端方案资源统一部署,没有解决在资源分布式部署后,前端跨域调用资源的问题,包括但不限于接口请求,私有静态资源,内容分发网络(CDN,Content Delivery Network)静态资源,Web Worker资源等。
本申请实施例提供一种微前端系统,该系统提供应用加载器模块配置为加 载各个不同框架的前端应用,如Vue框架、React框架等;实现JavaScript沙盒机制,保证JS环境隔离;该系统还提供子应用Web Worker的跨域处理,通过子应用打包注入CSS前缀、子应用运行时注入CSS前缀、子应用Shadow Dom方式加载等方式实现CSS隔离,提供包括Props传递、Custom Event、PostMessage在内的三种父子应用通信机制,提供一个路由注册服务,提供中心化的路由发现能力,且兼容支持原始Iframe下的运行。
下面说明本申请实施例提供的微前端系统的示例性应用,图1为本申请实施例提供的微前端系统的组成结构示意图,如图1所示,该微前端系统100包括:路由注册服务101、命令行工具102和微前端运行框架103,其中,路由注册服务101,为独立维护运行的Node后端服务,配置为为主应用的微前端运行框架提供子应用的路由信息、子应用的加载方式和子应用的部署信息。通过提供路由注册服务,作为一个可独立维护运行的Node服务,提供很好的扩容,容灾能力,维护微前端的子应用的注册和加载路由。
作为示例,路由注册服务可以是一个提供超文本传输协议(HTTP,Hyper Text Transfer Protocol)服务的服务器,在实际实现时可以由Node.js实现,通过Koa框架实现一套记录路由、删除路由、查询路由、登录授权等功能的网页端服务器,数据库使用关系型数据库管理系统(例如MySQL)。路由注册服务101可以是由任何服务器或者语言实现同样功能的服务,如Java Spring Cloud,C++Server Kit等。
由于该路由注册服务是独立维护运行的Node后端服务,在该路由注册服务中还可以前置一个负载均衡服务,在获取到网络请求后,能够基于各个路由注册服务的负载,将网络请求分配至负载较小的路由注册服务,并且在多个路由注册服务的负载都较大时,还能提供很好的扩容和容灾能力。
命令行工具102,配置为通过命令行提供新建子应用功能、接入子应用功能、服务注册功能。
作为示例,可以通过Inquirer.js提供一个用户与命令行交互的工具,也即该 命令行工具102,在实现时,该命令行工具可以是命令行界面(CLI,command-line interface)工具,还可以是npm库或者图形用户界面(GUI,Graphical Us er Interface)工具。通过该命令行工具102可以接收用户输入的用户新建子应用、接入子应用等命令,并基于接收到的命令进行服务注册。
微前端运行框架103,为运行在主应用的框架,配置为基于获取到的网络请求加载并运行子应用,并能够提供多框架下的子应用运行能力。
作为示例,主应用也即任意接入微前端运行框架的应用。在实现时,微前端运行框架可以是基于Single-SPA提供多框架子应用加载能力。
本申请实施例提供的微前端系统,包括路由注册服务、命令行工具和微前端运行框架,其中,路由注册服务,为独立维护运行的Node后端服务,如此能够提供很好的扩容和容灾能力,该路由注册服务为主应用的微前端运行框架提供子应用的路由信息、加载方式和子应用的部署信息;命令行工具,配置为通过命令行提供新建子应用、接入子应用、服务注册功能;微前端运行框架,为运行在主应用的框架,配置为基于获取到的网络请求加载并运行子应用,并能够提供多框架下的子应用运行能力。
在一些实施例中,如图1所示,微前端系统还包括:与路由注册服务对应的前端界面104,通过前端界面104获取针对子应用注册需要设置的子应用注册信息,并将子应用注册信息发送至路由注册服务。
子应用注册信息包括:子应用框架、子应用路由模式、子应用加载模式。例如,子应用框架可以包括Vue、React等,子应用路由模式可以包括哈希模式(hash)、历史(history)模式等,子应用加载模式可以包括:JS加载模式、CSS加载模式、HTML加载模式等。
在一些实施例中,子应用注册信息还可以包括服务名称、子应用本地开发环境地址、子应用线上环境地址等。
路由注册服务101,配置为接收子应用注册信息,并基于子应用注册信息注册子应用。
在一些实施例中,该命令行工具102配置为接收新建子应用命令,获取子应用的路由信息、资源信息和子应用模板信息。
在本申请实施例中,子应用的路由信息可以包括:子应用资源地址和子应用资源注册路径,子应用的资源信息可以包括子应用资源名、子应用资源类型,子应用模板信息可以包括模板标识。
命令行工具102基于子应用模板信息生成子应用模板,并向路由注册服务101发送子应用新建请求,子应用新建请求中携带有路由信息和资源信息。在一些实施例中,路由注册服务101接收到子应用新建请求后,基于该子应用新建请求中携带的路由信息和资源信息新建子应用。
在本申请实施例中,在命令行工具102向路由注册服务发送子应用新建请求之后,命令行工具102向部署服务器发送子应用部署请求,部署服务器基于部署请求中的子应用资源地址进行资源部署。
在一些实施例中,命令行工具102,还配置为接收接入子应用命令,获取子应用的路由信息和资源信息,并向路由注册服务101发送子应用接入请求,子应用接入请求中携带有子应用的路由信息和资源信息;
路由注册服务101,还配置为接收子应用接入请求,并基于子应用的路由信息和资源信息进行子应用注册。
在一些实施例中,图1所示的微前端运行框架103的组成结构如图2所示包括:基础功能库模块1031、通信模块1032、统一路由模块1033、子应用加载模块1034和子应用运行模块1035,其中:
基础功能库模块1031,配置为提供公共方法和公共组件,通过全局变量和函数的方式将公共方法和公共组件注入到子应用,供子应用使用。
在一些实施例中,基础功能库模块还可以提供常见的Polyfilling供子应用使用。
通信模块1032,配置为支持主应用到子应用、子应用到子应用和子应用到主应用的通信机制。
在本申请实施例中,主应用到子应用的通信机制包括道具Props传输和自定义事件Custom Event传输,子应用到子应用的通信机制包括不同源脚本异步PostMessage传输,子应用到主应用的通信机制包括Custom Event传输。Props传输可以提供响应式的双向数据传递能力;Custom Event可以基于组件定义事件的分发和注册,避免应用过多后无关事件影响;PostMessage提供全局的事件发送与接收,用于实现广播类的消息通知。本申请实施例中,在各个通信维度都有相应的实现方案,手段丰富,副作用小。
本申请实施例提供三种通信支持,包括Props传输,Custom Event传输,PostMessage传输,Props传输可以提供响应式的双向数据传递能力,Custom Event传输可以基于组件定义事件的分发和注册,避免应用过多后无关事件影响,PostMessage传输提供全局的事件发送与接收,配置为实现广播类的消息通知,在各个通信维度都有响应的实现方案,手段丰富,副作用小。
统一路由模块1033,配置为监听浏览器路由变更。
在实现时,统一路由模块1033利用Single-SPA来监听浏览器路由变更,加载和激活、运行指定框架下的子应用或主应用子路径,主应用初始化时从路由注册服务拉取该统一路由模块1033下的子应用注册路径,资源等信息。
子应用加载模块1034,配置为基于从路由注册服务获取到的子应用资源地址,获取并加载子应用资源地址对应的资源。
作为示例,子应用加载模块1034在加载子应用资源地址对应的资源时,会根据子应用注册信息中的子应用加载模式对子应用资源进行加载,其中,该子应用加载模块加载子应用的模式至少包括HTML实体模式、JS实体模式和Iframe模式。当加载模式为HTML实体模式时,加载HTML文件,当加载模式为JS实体模式时加载JS文件,当加载模式为Iframe模式时,直接将URL嵌到Iframe里打开。
在一些实施例中,子应用加载模块1034,在获取到子应用资源地址对应的资源后,基于该资源获取子应用的业务代码,并对获取到的子应用的业务代码进行解析,并将解析后的业务代码传输至子应用运行模块1035。
子应用运行模块1035,配置为运行子应用资源地址对应的资源,以渲染出子应用页面。
子应用运行模块1035,包括运行环境沙箱,在子应用运行模块得到解析后的业务代码,将解析后的业务代码在运行环境沙箱中执行。
在实际实现时,运行环境沙箱包括:JS沙箱、CSS沙箱和Web Worker沙箱。利用with语句和代理实现基本的JS沙箱,在子应用可控的情况下做到基本安全,通过堆栈检查,关键字检查来克服作用域逃逸手段。其中,代理是子应用可访问的对象集合,JS沙箱能够让子应用的业务代码只能访问代理里面可访问的对象,不能访问其他子应用或者主应用的对象。当解析后的业务代码在JS沙箱中执行时,解析后的业务代码,以代理作为全局根对象放入沙箱中执行,也就是说业务代码只能访问到代理的对象以及属性而不能影响到外层的其他变量,做到安全的隔离。
在本申请实施例中提供三种CSS沙箱手段:一是基于子应用webpack打包前缀,子应用webpack打包前缀也即为每个子应用的样式分配单独的命名空间,如此避免样式互相影响;二是基于子应用运行时前缀,在子应用运行时动态为子应用的样式增加前缀,来避免样式的冲突;三是基于Shadow Dom,基于Shadow Dom的CSS沙箱能够提供浏览器级别的样式隔离能力,可以做到完全隔离。
Web Worker沙箱,配置为内联运行分配给Web Worker的脚本文件,以实现Web Worker的跨域调用。
子应用资源加载模块在加载资源时劫持*.worker.js的文件,把该文件作为文本内容加载回浏览器内存中,利用Web Worker沙箱内联运行Web Worker的脚本文件(*.worker.js),内联运行的Web Worker脚本文件不会产生跨域问题,从而解决Web Worker的跨域问题。
在一些实施例中,微前端系统还包括支持跨域资源共享的服务器。在实现时,该服务器自动带有跨源资源共享(CORS,Cross-origin Resource Sharing)头,从而能够支持跨域资源共享,使得浏览器可以跨域访问私有静态资源、CD N静态资源。
本申请实施例提供包括接口资源在内的服务器端CORS方案支持跨域,CDN静态资源提供CORS方案,Web Worker提供内联构建加载器和内联运行加载器解决跨域调用worker问题。本申请实施例还提供缓存,预加载,Web Worker等手段加速子应用的加载和调用。
在一些实施例中,如图2所示,微前端运行框架103还包括:数据管理模块1036、性能监控模块1037和错误处理模块1038,其中:
数据管理模块1036,配置为通过Props传输机制提供的数据,实现数据双向绑定功能,从而共享父子应用的数据。
在本申请实施例中,父子应用在一个相同的运行环境中加载的,主应用会传一个有监听功能的对象给子应用,子应用变更的时候能够被该对象监听到,从而能够实现父子应用数据的共享。
性能监控模块1037,配置为监控子应用的加载时长、运行时长。
在实现时,主应用通过预设的函数监控子应用的加载时长,运行时长等信息。
错误处理模块1038,配置为监控并处理子应用在加载和运行过程中的错误信息。
在实现时,主应用通过注册window.addEventListener('error',errorHandler)、window.addEventListener('unhandledrejection',errorHandler)来监控子应用报错并处理,从而能够及时处理子应用的错误信息,保证微前端系统的可靠性。
基于前述实施例提供的微前端系统,本申请实施例再提供一种基于微前端系统的子应用加载方法,应配置为上述实施例提供的微前端系统,图3为本申请实施例提供的基于微前端系统的子应用加载方法的实现流程示意图,如图3所示,该方法包括:
步骤S301,获取网络访问请求。
作为示例,该网络访问请求中携带有URL地址。该网络访问请求可以是由用户的网络访问操作而触发的。该功能网络访问请求可以是配置为访问主应用的请求,还可以是访问子应用的请求。当该网络访问请求为访问子应用的网络访问请求时,可以是用户在浏览器中输入主应用的URL地址,并且浏览器渲染出主应用界面后,用户基于主应用界面中提供的子应用的图标而触发对子应用的网络访问请求。
在本申请实施例中,在步骤S301之前,该微前端系统已经完成了主应用部署和路由注册服务的部署,并且已通过CLI工具完成子应用创建和注册。
步骤S302,基于URL地址从微前端系统的路由注册服务拉取对应的路由信息。
作为示例,步骤S302在实现时,可以是将URL地址发送至路由注册服务,路由注册服务根据该URL地址,确定要访问的应用标识,然后在基于该应用标识拉取对应的路由信息。
步骤S303,当基于路由信息确定待访问页面为子应用页面时,微前端系统的子应用加载模块基于路由信息,向路由注册服务获取路由信息对应的子应用资源。
作为示例,在获取到应用对应的路由信息之后,如果确定待访问页面为子应用页面时,路由注册服务即可根据该路由信息,获取对应的子应用资源,例如可以是CSS、JS等静态资源文件。
步骤S304,当需要加载子应用资源时,子应用加载模块加载子应用资源。
在本申请实施例中,子应用加载模块在获取到子应用资源后,首先要判断是否需要加载该子应用资源,当需要加载子应用资源时再基于子应用的加载模式加载子应用资源,当确定不需要加载子应用资源时,说明该子应用资源已经进行过了加载,此时直接运行该子应用资源,以渲染子应用页面。
步骤S305,微前端系统的子应用运行模块运行子应用资源,以渲染出子应用的页面。
在一些实施例中,子应用加载模块在获取到子应用资源后,基于该子应用 资源获取子应用的业务代码,并对获取到的子应用的业务代码进行解析,并将解析后的业务代码传输至子应用运行模块。子应用运行模块得到解析后的业务代码,将解析后的业务代码在自身运行环境沙箱中执行,以渲染出子应用的页面。
在实际实现时,运行环境沙箱包括:JS沙箱、CSS沙箱和Web Worker沙箱。其中:利用with语句和代理实现基本的JS沙箱,在子应用可控的情况下做到基本安全,通过堆栈检查,关键字检查来克服作用域逃逸手段。其中,代理是子应用可访问的对象集合,JS沙箱能够使得子应用的业务代码只能访问代理里面可访问的对象,不能访问其他子应用或者主应用的对象。当解析后的业务代码在JS沙箱中执行时,解析后的业务代码,以代理作为全局根对象放入沙箱中执行,也就是说业务代码只能访问到代理的对象以及属性而不能影响到外层的其他变量,做到安全的隔离。
在本申请实施例中提供三种CSS沙箱手段:一是基于子应用webpack打包前缀,子应用webpack打包前缀也即为每个子应用的样式分配单独的命名空间,如此避免样式互相影响;二是基于子应用运行时前缀,通过子应用运行时动态加载卸载应用样式来避免样式的冲突;三是基于Shadow Dom,基于Shadow Dom的CSS沙箱能够提供浏览器级别的样式隔离能力,可以做到完全隔离。
Web Worker沙箱,配置为内联运行分配给Web Worker的脚本文件,以实现Web Worker的跨域调用。子应用资源加载模块在加载资源时劫持*.worker.js的文件,把该文件作为文本内容加载回浏览器内存中,利用Web Worker沙箱内联运行Web Worker的脚本文件(*.worker.js),内联运行的Web Worker脚本文件不会产生跨域问题,从而解决Web Worker的跨域问题。
在本申请实施例提供的基于微前端系统的子应用加载方法中,在获取到网络访问请求之后,基于网络访问请求中携带的URL地址,从微前端系统的路由注册服务拉取对应的路由信息,当基于路由信息确定待访问页面为子应用页面时,微前端系统的子应用加载模块基于路由信息,从路由注册服务获取路由信息对应的子应用资源,在需要加载子应用资源时,子应用加载模块加载子应用 资源再由微前端系统的子应用运行模块运行子应用资源,以渲染出子应用的页面。
在一些实施例中,如图4所示,在步骤S304之前,该基于微前端系统的子应用加载方法还包括:
步骤S003,确定子应用资源是否被预加载或者是否被打开。
作为示例,当子应用资源没有被预加载并且没有被打开时,确定子应用资源需要被加载,此时进入步骤S304;当子应用资源已经被预加载或者已经被打开时,确定子应用资源不需要再次加载,此时进入步骤S305。如此能够加速子应用的加载和调用。
在一些实施例中,在进行子应用加载之前,需要先进行子应用的注册和部署,子应用注册过程可以通过以下步骤实现:
步骤S001,获取针对子应用注册需要设置的子应用注册信息,并将子应用注册信息发送至路由注册服务。
作为示例,子应用注册信息至少包括:子应用框架、子应用路由模式、子应用加载模式。
在微前端系统中可以包括与路由注册服务对应的前端界面,还可以包括配置为新建子应用及接入子应用的命令行工具,对应地,步骤S001在实现时,有两种实现方式:
一、通过路由注册服务对应的前端界面,获取针对子应用注册的输入操作,并基于输入操作确定子应用注册信息。
当基于第一种方式获取子应用注册信息时,首先要基于打开该前端界面的操作指令呈现该前端界面,然后通过该前端界面接收针对子应用注册的输入操作,该输入操作为输入子应用注册需要设置的参数,例如可以包括:服务名称、子应用框架、子应用本地开发环境地址、子应用线上环境地址、子应用注册子路由、子应用路由模式(hash或者history)、子应用加载模式等。
在一些实施例中,该前端界面还提供有确定注册的图形控件,在用户确定完成对子应用注册信息的设置后,可以点击或者触控该图形控件,以将子应用注册信息发送至路由注册服务。在将子应用注册信息发送给路由注册服务时,可以是通过向路由注册服务发送一个子应用注册的HTTP请求,该HTTP请求中可以携带有子应用注册信息。
二、通过命令行工具接收新建子应用命令,获取针对新建子应用的输入操作,并基于输入操作确定子应用注册信息。
与第一种实现方式类似,在基于命令行工具获取子应用注册信息时,首先要启动命令行工具,然后通过该命令行工具接收新建子应用命令,并进而获取针对新建子应用的输入操作,该输入操作为输入子应用注册需要设置的参数,继而根据该输入操作获取子应用注册信息,例如可以包括子应用资源名、子应用资源地址、子应用资源类型、子应用资源注册路径等信息,在实现时,还需要通过命令行工具选择子应用模板标识,然后由命令行工具自动生成对应模板并注入子应用资源地址、子应用资源注册地址等信息。在将子应用注册信息发送至路由注册服务时,可以是通过输入发送信息命令,基于该发送信息命令把子应用注册信息发送到路由注册服务。
步骤S002,路由注册服务接收子应用注册信息,并基于子应用注册信息注册子应用。
通过上述的步骤S001至步骤S002,利用该微前端系统,能够自行对子应用的路由信息和资源信息进行注册,从而提高注册子应用的灵活性。
在一些实施例中,图3所示的步骤S304“当需要加载子应用资源时,子应用加载资源加载子应用资源”可以通过以下步骤实现:
步骤S3041,当需要加载子应用资源时,获取子应用的框架标识和资源加载模式。
作为示例,子应用的框架标识可以包括Vue、React等,资源加载模式可以包括:JS实体加载模式、CSS实体加载模式、Iframe加载模式等。
步骤S3042,根据资源加载类型,在框架标识对应的子应用框架中加载子应用资源。
作为示例,当加载模式为HTML实体模式时,加载HTML文件,当加载模式为JS实体模式时加载JS文件,当加载模式为Iframe模式时,直接将URL嵌到Iframe里打开。
在一些实施例中,如图5所示,在步骤S302之后,还可以执行以下步骤:
步骤S201,基于路由信息确定待访问页面是否为主应用页面。
作为示例,当基于路由信息确定待访问页面为主应用页面时,执行步骤S202;当基于路由信息确定待访问页面为子应用页面时,进入步骤S303。
步骤202,根据生命周期确定主应用当前挂载的子应用。
步骤S203,从当前挂载的子应用中确定要渲染的目标子应用。
作为示例,步骤S203可以是根据预设规则从当前挂载的子应用中确定要渲染的至少一个目标子应用,例如可以是从当前挂载的子应用中选择访问次数最多的一个或多个确定为目标子应用。
步骤S204,基于暴露的加载函数和目标子应用,模拟路由切换,获取目标子应用的子应用资源和主应用资源。
作为示例,在待访问页面为主应用页面时,那么首先会根据路由信息获取主应用资源。在本申请中,由于加载函数是暴露的,那么加载函数可以被主应用主动调用,当主应用主动调用暴露的加载函数时,能够模拟路由切换,从而触发微前端系统的子应用加载模块获取目标子应用的子应用资源。
步骤S205,加载并运行主应用资源和子应用资源,以在渲染出的主应用的页面中渲染出子应用。
步骤S205在实现时,首先加载并运行主应用资源,以渲染出主应用界面,进而再运行子应用资源,也渲染出子应用页面,如此主应用可以主动渲染子应用,而不用依赖于路由注册。
在上述步骤S201至步骤S205所在的实施例中,当待访问页面为主应用页 面时,可以根据主应用的生命周期确定出当前挂载的子应用,并基于预设原则确定出目标子应用,并且通过调用暴露的加载函数,模拟路由切换,获取目标子应用的子应用资源,并在渲染出的主应用页面中显示子应用页面,从而实现主应用对子应用的主动渲染。
下面,将说明本申请实施例在一个实际的应用场景中的示例性应用。
图6为本申请实施例提供的微前端系统示意图,如图6所示,该微前端系统包括:路由注册服务601与该路由注册服务相应的前端页面、子应用接入和生成的CLI工具602、主应用的微前端运行框架603。
路由注册服务601,为微前端运行框架603提供子应用的路由信息、加载方式以及子应用的部署信息。
在实现时,可以提供一个前端界面以进行子应用路由注册,通过该页面可以对路由注册需要的参数进行设置,需要设置的参数包括但不限于:服务名称、子应用框架、子应用本地开发环境地址、子应用线上环境地址、子应用注册子路由、子应用路由模式(hash或者history)、子应用加载模式。
路由注册服务601是一个提供HTTP服务的服务器,主要由Node.js实现,通过Koa框架实现一套记录路由、删除路由、查询路由、登录授权等功能的网页服务器,数据库可以使用MySQL,也可以使用其他形式的数据库。
在实现时,路由注册服务可以是Node后端服务,通过该Node后端服务接收子应用的注册信息,应用加载器通过该Node后端服务解析和发现子应用,并通过信息确定如何加载子应用的资源。多个Node单服务通过PM2启动,PM2是一个带有负载均衡功能的Node应用进程管理器另外路由注册服务中还可以包括一个负载均衡服务,配置为提供服务的容灾保活和扩容能力。
CLI工具602,提供包括新建子应用、接入子应用、服务注册和部署等功能。
在实现时,通过Inquirer.js提供一套命令行工具,提供包括新建子应用、接入子应用、服务注册和部署等功能。
新建子应用在实现时,可以是用户首先在命令行输入新建子应用命令,并 填写子应用资源名、子应用资源地址、子应用资源类型、子应用资源注册路径,并选择子应用模板,CLI工具自动生成对应模板并注入路由信息,并把资源信息自动注册到路由注册服务。
接入子应用在实现时,可以是用户在命令行输入接入子应用命令,并填写子应用资源名、子应用资源地址、子应用资源类型、子应用资源注册路径,CLI工具自动寻找子应用入口文件,并添加主应用所需的生命周期函数,CLI工具自动把资源信息自动注册到路由注册服务。
服务注册功能在实现时,CLI工具通过携带新建子应用命令,并填写子应用资源名、子应用资源地址、子应用资源类型、子应用资源注册路径等参数,通过HTTP请求发送给路由注册服务。
部署功能在实现时,CLI工具通过HTTP请求发送部署请求至路由注册服务。
微前端运行框架603,是一个运行在主应用的框架,主应用还可以称为父应用或者应用程序外壳(APP shell),APP shell包括一个公共资源库、应用加载器、资源装载器(Single-SPA的封装)和运行环境沙箱。运行环境沙箱包括js沙箱、Web Worker内联沙箱和CSS环境隔离沙箱。APP shell也支持Iframe模式的运行。
主应用是任意接入微前端运行框架的应用。
如图6中的603所示,该微前端运行框架包括基础功能库、通信模块、数据管理模块、性能监控模块、错误处理模块、统一路由模块、子应用加载模块和子应用运行模块。
基础功能库,提供常见的polyfills、公共方法和组件,通过全局变量和函数等方式注入到子应用,供子应用使用。
通信模块,通过Custom Event提供事件通信,通过PostMessage提供消息通信,通过生命周期中Props传递提供系统数据通信。
图7为本申请实施例提供的微前端系统中通信机制的示意图,如图7所示,主应用到子应用的通信方式可以包括:Props和Custom Event两种通信机制, 子应用到主应用的通信方式可以包括:Custom Event(组件)和Custom Event(window)两种通信机制,子应用与子应用之间的通信方式包括:PostMessage和广播信道(BroadcastChannel)两种通信方式。
数据管理模块,通过Props提供的数据,可以实现数据双向绑定功能,共享父子应用的数据。
性能监控模块,配置为实现主应用通过函数对子应用的加载时间,运行时间等数据的监控。
错误处理模块,配置为监控并处理子应用在加载和运行过程中的错误信息。
作为示例,主应用通过注册监听器来监控子应用报错并处理,其中,所注册的监听器包括window.addEventListener('error',errorHandler)和window.addEventListener('unhandledrejection',errorHandler)。
统一路由模块,利用Single-SPA来监听浏览器路由变更,加载和激活运行指定框架下的子应用或主应用子路径,主应用初始化时从路由注册服务拉取该统一路由模块下的子应用注册路径,资源等信息。
子应用加载模块,配置为加载子应用资源。
图8为本申请实施例提供的子应用加载模块加载子应用资源的实现流程示意图,如图8所示,该流程包括:
步骤S801,基于获取到的网络请求,从路由注册服务拉取路由以及静态资源。
作为示例,该网络请求中携带有URL地址,步骤S801在实现时,可以是基于该URL地址从路由注册服务确定该URL地址对应的应用标识,路由注册服务再根据该应用标识确定对应的路由信息,并基于路由信息获取静态资源。
步骤S802,资源加载器加载子应用资源。
资源加载器可以加载不同框架的子应用,并且可以加载HTML Entry,JS Entry模式和Iframe模式,HTML模式通过HTML中的引用资源加载静态文件,js模式通过js中的动态加载资源,也提供传统的Iframe模式加载子应用。
在本申请实施例中,考虑到性能和跨域影响,资源加载器还可以提供预加 载、缓存、idle加载等手段。
步骤S803,在资源加载器加载出子应用资源后,进行资源信息注册。
作为示例,在资源加载器加载出子应用资源后,在内存里注册加载出的子应用资源信息。
子应用加载模块包括资源加载器和资源装载器,其中,资源装载器是基于Single-SPA的封装,能够提供多前端框架下的子应用运行能力,Single-SPA提供了路由监听的功能,在应用路由切换时,会根据生命周期,加载对应子应用的框架代码和业务代码,从而实现运行不同框架和多级路由激活能力;并且通过暴露加载函数,模拟路由切换,实现主应用主动调用激活能力。
子应用运行模块,包括JS沙箱和CSS沙箱(非传统的Iframe模式存在),子应用运行模块负责加载子应用加载模块拉取回来的js资源等。
JS沙箱设计如图9所示,利用with函数901和代理902实现基本的js沙箱,在本申请实施例中,能够实现Proxy代理和快照代理模式,快照代理模式兼容不支持ES6Proxy的环境。如图9所示,通过应用加载器的资源加载器解析后的子应用实际代码903,放入代理沙箱中执行。并且对于常见的作用域逃逸手段,通过堆栈检查,关键字检查来进行防止,从而在子应用可控的情况下做到基本安全。
在本申请实施例中,提供以下三种CSS沙箱手段:
第一、基于子应用webpack打包前缀。子应用需要统一接入打包工具,并对每个子应用的样式分配单独的命名空间;
第二、基于子应用运行时前缀。
某些样式很难支持,例如@keyframes,@font-face,@import等,并且动态加载的<link>样式需要特殊处理,因此可以在子应用运行时,为子应用的样式增加前缀,来避免样式的冲突。
第三、基于Shadow Dom。Shadow Dom需要处理shadow边界、事件丢失、访问控制(shadowRoot)等问题。
本申请实施例提供的微前端系统,提供路由注册服务,作为一个可独立维 护运行的Node服务,提供很好的扩容,容灾能力,维护微前端的子应用的注册和加载路由;并且基于Single-SPA提供多框架下的子应用运行能力,基于定制化的加载方案,提供主应用主动渲染子应用能力,不一定需要依赖路由注册;另外在通信机制上供三种通信支持,包括Props传递,Custom Event,PostMessage,Props传递可以提供响应式的双向数据传递能力,Custom Event可以基于组件定义事件的分发和注册,避免应用过多后无关事件影响,PostMessage提供全局的事件发送与接收,配置为实现广播类的消息通知,在各个通信维度都有响应的实现方案,手段丰富,副作用小;该微前端系统提供包括接口资源在内的服务器端CORS方案支持跨域,私有静态资源、CDN静态资源提供CORS方案支持跨域,Web Worker提供内联构建加载器和内联运行时加载器解决跨域调用worker问题,还提供缓存,预加载,Web Worker等手段加速子应用的加载和调用;并且提供运行时加载子应用的方案,可以在运行时改变子应用渲染内容,交互逻辑,提供更高自由性。
本申请实施例提供了一种计算机程序产品或计算机程序,该计算机程序产品或计算机程序包括计算机指令,该计算机指令存储在计算机可读存储介质中。计算机设备的处理器从计算机可读存储介质读取该计算机指令,处理器执行该计算机指令,使得该计算机设备执行本申请实施例上述的基于微前端系统的子应用加载方法。
本申请实施例提供一种存储有可执行指令的存储介质,其中存储有可执行指令,当可执行指令被处理器执行时,将引起处理器执行本申请实施例提供的子应用加载方法,例如,如图3、图4及图5示出的子应用加载方法。
在一些实施例中,存储介质可以是计算机可读存储介质,例如,铁电存储器(FRAM,Ferromagnetic Random Access Memory)、只读存储器(ROM,Read Only Memory)、可编程只读存储器(PROM,Programmable Read Only Memory)、可擦除可编程只读存储器(EPROM,Erasable Programmable Read Only Memory)、带电可擦可编程只读存储器(EEPROM,Electrically Erasable Programmable Read Only Memory)、闪存、磁表面存储器、光盘、或光盘只读 存储器(CD-ROM,Compact Disk-Read Only Memory)等存储器;也可以是包括上述存储器之一或任意组合的各种设备。
在一些实施例中,可执行指令可以采用程序、软件、软件模块、脚本或代码的形式,按任意形式的编程语言(包括编译或解释语言,或者声明性或过程性语言)来编写,并且其可按任意形式部署,包括被部署为独立的程序或者被部署为模块、组件、子例程或者适合在计算环境中使用的其它单元。
作为示例,可执行指令可以但不一定对应于文件系统中的文件,可以可被存储在保存其它程序或数据的文件的一部分,例如,存储在超文本标记语言(HTML,Hyper Text Markup Language)文档中的一个或多个脚本中,存储在专配置为所讨论的程序的单个文件中,或者,存储在多个协同文件(例如,存储一个或多个模块、子程序或代码部分的文件)中。作为示例,可执行指令可被部署为在一个计算设备上执行,或者在位于一个地点的多个计算设备上执行,又或者,在分布在多个地点且通过通信网络互连的多个计算设备上执行。
以上所述,仅为本申请的实施例而已,并非配置为限定本申请的保护范围。凡在本申请的精神和范围之内所作的任何修改、等同替换和改进等,均包含在本申请的保护范围之内。

Claims (20)

  1. 一种微前端系统,所述微前端系统包括:
    路由注册服务、命令行工具和微前端运行框架,其中,
    所述路由注册服务,为独立维护运行的节点Node后端服务,配置为为主应用的微前端运行框架提供子应用的路由信息、所述子应用的加载方式和所述子应用的部署信息;
    所述命令行工具,配置为通过命令行提供新建子应用功能、接入子应用功能、服务注册功能;
    所述微前端运行框架,为运行在所述主应用的框架,配置为基于获取到的网络请求加载并运行所述子应用,并提供多框架下的子应用运行能力。
  2. 根据权利要求1中所述的微前端系统,其中,所述微前端系统还包括:
    与所述路由注册服务对应的前端界面,配置为获取针对子应用注册需要设置的子应用注册信息,并将所述子应用注册信息发送至所述路由注册服务,所述子应用注册信息包括:子应用框架、子应用路由模式、子应用加载模式;
    所述路由注册服务,还配置为接收所述子应用注册信息,并基于所述子应用注册信息注册所述子应用。
  3. 根据权利要求1中所述的微前端系统,其中,
    所述命令行工具,还配置为接收新建子应用命令,获取所述子应用的路由信息、所述子应用的资源信息和子应用模板信息;
    所述命令行工具,还配置为基于所述子应用模板信息生成子应用模板,并向所述路由注册服务发送子应用新建请求,所述子应用新建请求中携带有所述路由信息和所述资源信息;
    所述命令行工具,还配置为向部署服务器发送子应用部署请求,其中,所述子应用部署请求用于触发所述部署服务器基于所述子应用部署请求中的子应用资源地址进行资源部署。
  4. 根据权利要求2中所述的微前端系统,其中,
    所述命令行工具,还配置为接收接入子应用命令,获取所述子应用的路由信息和所述子应用的资源信息;
    所述命令行工具,还配置为向所述路由注册服务发送子应用接入请求,所述子应用接入请求中携带有所述子应用的路由信息和资源信息;
    所述路由注册服务,还配置为接收所述子应用接入请求,并基于所述子应用的路由信息和资源信息进行子应用注册。
  5. 根据权利要求1所述的微前端系统,其中,
    所述微前端运行框架包括:基础功能库模块、通信模块、统一路由模块、子应用加载模块和子应用运行模块,其中,
    所述基础功能库模块,配置为提供公共方法和公共组件,并通过全局变量和函数的方式将所述公共方法和所述公共组件注入到所述子应用,供所述子应用使用;
    所述通信模块,配置为支持所述主应用到所述子应用、所述子应用到所述子应用和所述子应用到所述主应用的通信机制;
    所述统一路由模块,配置为监听浏览器路由变更;
    所述子应用加载模块,配置为从所述路由注册服务获取子应用资源地址,获取并加载所述子应用资源地址对应的资源;
    所述子应用运行模块,配置为运行所述子应用资源地址对应的资源,并渲染出子应用页面。
  6. 根据权利要求5中所述的微前端系统,其中,所述主应用到子应用的通信机制包括道具Props传输和自定义事件Custom Event传输,所述子应用到子应用的通信机制包括发送消息PostMessage传输,所述子应用到主应用的通信机制包括Custom Event传输;
    所述子应用加载模块加载所述子应用的模式包括超文本标记语言HTML实体模式、脚本语言JS实体模式和页面嵌套Iframe模式。
  7. 根据权利要求5中所述的微前端系统,其中,所述微前端运行框架还包括:数据管理模块、性能监控模块、错误处理模块,其中:
    所述数据管理模块,配置为通过Props传输机制提供的数据,实现数据双向绑定功能;
    所述性能监控模块,配置为监控子应用的加载时长、运行时长;
    所述错误处理模块,配置为监控并处理子应用在加载和运行过程中的错误信息。
  8. 根据权利要求5中所述的微前端系统,其中,
    所述子应用加载模块,还配置为对获取到的所述子应用的业务代码进行解析,并将解析后的业务代码传输至所述子应用运行模块;
    所述子应用运行模块包括运行环境沙箱,所述解析后的业务代码在所述运行环境沙箱中执行。
  9. 根据权利要求8中所述的微前端系统,其中,所述运行环境沙箱包括:JS沙箱、层叠样式表CSS沙箱和后台脚本Web Worker沙箱。
  10. 根据权利要求9中所述的微前端系统,其中,所述Web Worker沙箱,配置为内联运行分配给Web Worker的脚本文件,并执行所述Web Worker的跨域调用。
  11. 根据权利要求1至10任一项所述的微前端系统,其中,所述微前端系统还包括支持跨域资源共享的服务器。
  12. 一种基于微前端系统的子应用加载方法,所述方法由电子设备执行,所述微前端系统包括:路由注册服务、子应用加载模块和子应用运行模块,所述方法包括:
    获取网络访问请求,所述网络访问请求中携带有待访问页面的统一资源定位符URL地址;
    基于所述URL地址从所述路由注册服务拉取对应的路由信息;
    当基于所述路由信息确定所述待访问页面为子应用页面时,所述子应用加载模块基于所述路由信息,从所述路由注册服务获取所述路由信息对应的子应用资源;
    当需要加载所述子应用资源时,所述子应用加载模块加载所述子应用资源;
    所述子应用运行模块运行所述子应用资源,并渲染出子应用的页面。
  13. 根据权利要求12中所述的方法,其中,所述方法还包括:
    确定所述子应用资源是否被预加载或者是否被打开;
    当所述子应用资源没有被预加载并且没有被打开时,确定所述子应用资源需要被加载。
  14. 根据权利要求12中所述的方法,其中,所述方法还包括:
    获取针对子应用注册需要设置的子应用注册信息,并将所述子应用注册信息发送至路由注册服务,所述子应用注册信息包括:子应用框架、子应用路由模式、子应用加载模式;
    通过所述路由注册服务接收所述子应用注册信息,并基于所述子应用注册信息注册所述子应用。
  15. 根据权利要求14中所述的方法,其中,所述获取针对子应用注册需要设置的子应用注册信息,包括:
    通过所述路由注册服务对应的前端界面,获取针对子应用注册的输入操作;
    基于所述输入操作确定所述子应用注册信息;或者,
    通过命令行工具接收新建子应用命令,获取所述子应用的路由信息、所述子应用的资源信息和子应用模板信息。
  16. 根据权利要求12中所述的方法,其中,所述当需要加载所述子应用资源时,所述子应用加载模块加载所述子应用资源,包括:
    当需要加载所述子应用资源时,获取所述子应用的框架标识和资源加载类型;
    根据所述资源加载类型,在所述框架标识对应的子应用框架中加载所述子应用资源。
  17. 根据权利要求12至16任一项所述的方法,其中,所述方法还包括:
    当基于所述路由信息确定待访问页面为主应用页面时,根据生命周期确定主应用当前挂载的子应用;
    从所述当前挂载的子应用中确定要渲染的目标子应用;
    基于暴露的加载函数和所述目标子应用,模拟路由切换,并获取所述目标子应用的子应用资源和主应用资源;
    加载并运行所述子应用资源和所述主应用资源,并在渲染出的所述主应用的页面中渲染出子应用。
  18. 一种计算机可读存储介质,存储有可执行指令,用于被处理器执行时,实现权利要求12至17任一项所述的基于微前端系统的子应用加载方法。
  19. 一种电子设备,包括存储器和处理器,所述存储器中存储有计算机程序,所述处理器被设置为通过所述计算机程序执行所述权利要求12至17任一项中所述的基于微前端系统的子应用加载方法。
  20. 一种计算机程序产品,包括计算机程序,所述计算机程序被处理器执行时实现权利要求12至17任一项所述的基于微前端系统的子应用加载方法。
PCT/CN2021/137072 2020-12-21 2021-12-10 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质 WO2022135178A1 (zh)

Priority Applications (3)

Application Number Priority Date Filing Date Title
KR1020237010638A KR20230054474A (ko) 2020-12-21 2021-12-10 마이크로프론트엔드 시스템, 서브애플리케이션 로딩 방법, 전자 디바이스, 컴퓨터 프로그램 제품 및 컴퓨터로 판독 가능한 저장 매체
JP2023515655A JP7451825B2 (ja) 2020-12-21 2021-12-10 マイクロフロントエンドシステム、サブアプリケーションロード方法、電子機器、及びコンピュータープログラム製品
US17/962,218 US20230036980A1 (en) 2020-12-21 2022-10-07 Micro-frontend system, sub-application loading method, electronic device, computer program product, and computer-readable storage medium

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011520184.6A CN114647518A (zh) 2020-12-21 2020-12-21 微前端系统、子应用加载方法及计算机可读存储介质
CN202011520184.6 2020-12-21

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US17/962,218 Continuation US20230036980A1 (en) 2020-12-21 2022-10-07 Micro-frontend system, sub-application loading method, electronic device, computer program product, and computer-readable storage medium

Publications (1)

Publication Number Publication Date
WO2022135178A1 true WO2022135178A1 (zh) 2022-06-30

Family

ID=81990618

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/137072 WO2022135178A1 (zh) 2020-12-21 2021-12-10 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质

Country Status (5)

Country Link
US (1) US20230036980A1 (zh)
JP (1) JP7451825B2 (zh)
KR (1) KR20230054474A (zh)
CN (1) CN114647518A (zh)
WO (1) WO2022135178A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115277637A (zh) * 2022-09-26 2022-11-01 中企云链(北京)金融信息服务有限公司 基于微前端架构的多域名项目的管理平台及高度聚合部署方法
CN115828021A (zh) * 2022-12-21 2023-03-21 北京深盾科技股份有限公司 一种网页通信方法、系统、电子设备及存储介质
CN115987959A (zh) * 2022-12-02 2023-04-18 浪潮通信信息系统有限公司 一种基于远端加载的可定制app融合方法
CN116301870A (zh) * 2023-05-17 2023-06-23 北京天信瑞安信息技术有限公司 微前端框架及其构建方法和相关设备

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116501364B (zh) * 2023-05-05 2024-06-07 南京领行科技股份有限公司 一种应用注册方法、装置和微前端系统
CN116301759B (zh) * 2023-05-12 2023-11-03 国网信息通信产业集团有限公司 一种移动组件共享方法、系统、设备及存储介质
CN116506215B (zh) * 2023-06-16 2023-09-12 中国联合网络通信集团有限公司 访问处理方法、装置、电子设备以及存储介质
CN116700834B (zh) * 2023-08-07 2023-10-24 天津华来科技股份有限公司 一种App模块化加载方法及系统

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160092339A1 (en) * 2014-09-26 2016-03-31 Oracle International Corporation Efficient means to test server generated applications on mobile device
CN106598575A (zh) * 2016-11-30 2017-04-26 武汉斗鱼网络科技有限公司 一种前端数据模拟的实现方法及系统
CN109542538A (zh) * 2018-11-22 2019-03-29 郑州云海信息技术有限公司 一种子系统管理方法和系统
CN110377274A (zh) * 2019-07-08 2019-10-25 紫光云技术有限公司 基于Single-Spa的微前端架构系统及开发、部署方法
CN110806895A (zh) * 2019-11-04 2020-02-18 精硕科技(北京)股份有限公司 一种项目创建方法、装置及计算机可读存储介质

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4152755B2 (ja) 2003-01-10 2008-09-17 富士通株式会社 新旧プログラムモジュールの切り替え機能を有するサーバ装置
US10678600B1 (en) 2019-03-01 2020-06-09 Capital One Services, Llc Systems and methods for developing a web application using micro frontends
CN110708368A (zh) 2019-09-25 2020-01-17 北京计算机技术及应用研究所 一种基于路由分发的微前端系统和方法
CN111796860B (zh) 2020-06-28 2024-01-30 中国工商银行股份有限公司 微前端方案实现方法及装置

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160092339A1 (en) * 2014-09-26 2016-03-31 Oracle International Corporation Efficient means to test server generated applications on mobile device
CN106598575A (zh) * 2016-11-30 2017-04-26 武汉斗鱼网络科技有限公司 一种前端数据模拟的实现方法及系统
CN109542538A (zh) * 2018-11-22 2019-03-29 郑州云海信息技术有限公司 一种子系统管理方法和系统
CN110377274A (zh) * 2019-07-08 2019-10-25 紫光云技术有限公司 基于Single-Spa的微前端架构系统及开发、部署方法
CN110806895A (zh) * 2019-11-04 2020-02-18 精硕科技(北京)股份有限公司 一种项目创建方法、装置及计算机可读存储介质

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115277637A (zh) * 2022-09-26 2022-11-01 中企云链(北京)金融信息服务有限公司 基于微前端架构的多域名项目的管理平台及高度聚合部署方法
CN115277637B (zh) * 2022-09-26 2023-01-13 中企云链(北京)金融信息服务有限公司 基于微前端架构的多域名项目的管理平台及高度聚合部署方法
CN115987959A (zh) * 2022-12-02 2023-04-18 浪潮通信信息系统有限公司 一种基于远端加载的可定制app融合方法
CN115828021A (zh) * 2022-12-21 2023-03-21 北京深盾科技股份有限公司 一种网页通信方法、系统、电子设备及存储介质
CN115828021B (zh) * 2022-12-21 2024-02-13 北京深盾科技股份有限公司 一种网页通信方法、系统、电子设备及存储介质
CN116301870A (zh) * 2023-05-17 2023-06-23 北京天信瑞安信息技术有限公司 微前端框架及其构建方法和相关设备

Also Published As

Publication number Publication date
JP2023541033A (ja) 2023-09-27
CN114647518A (zh) 2022-06-21
US20230036980A1 (en) 2023-02-02
KR20230054474A (ko) 2023-04-24
JP7451825B2 (ja) 2024-03-18

Similar Documents

Publication Publication Date Title
WO2022135178A1 (zh) 微前端系统、子应用加载方法、电子设备、计算机程序产品及计算机可读存储介质
CN108319483B (zh) 网页处理方法、装置、终端及存储介质
US9672140B1 (en) Processing special requests at dedicated application containers
US8266202B1 (en) System and method for auto-generating JavaScript proxies and meta-proxies
US8285813B1 (en) System and method for emulating different user agents on a server
JP5439190B2 (ja) It向けサーバベースのウェブアプリケーションを作成するための方法およびシステム
US8639743B1 (en) System and method for on-the-fly rewriting of JavaScript
US9798524B1 (en) System and method for exposing the dynamic web server-side
US20080288622A1 (en) Managing Server Farms
Lazuardy et al. Modern front end web architectures with react. js and next. js
CN113010170A (zh) 一种基于Vue3组件的页面渲染方法、装置、介质及电子设备
CN114706579A (zh) 页面开发方法、装置、服务器及存储介质
Aguilar SignalR Programming in Microsoft ASP. NET
Xu et al. Caople: A programming language for microservices saas
Peters Building rich internet applications with node. js and express. js
Larsson Hands-on Microservices with spring boot and spring cloud: Build and deploy Java microservices using spring cloud, Istio, and Kubernetes
WO2022146714A9 (en) System and method for real-time, dynamic creation, delivery, and use of customizable web applications
Jína Javascript test runner
Nyfløtt Optimizing inter-service communication between microservices
Hertel Aspects of AJAX
Penberthy et al. Serverless
Macero García et al. Event-Driven Architectures
Sreekumar Cross Platform Lightweight Social Networking Application for Next Generation E-Commerce
Lim et al. Jda: a step towards large-scale reuse on the web
CN115982257A (zh) 接口创建方法以及相关设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21909175

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2023515655

Country of ref document: JP

Kind code of ref document: A

ENP Entry into the national phase

Ref document number: 20237010638

Country of ref document: KR

Kind code of ref document: A

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21909175

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 021123)