Item processing method based on vitite and qiankun

By obtaining the entry file of vite for non-module import, and using the @vitejs/plugin-legacy plug-in for packaging and replacement, the sandbox failure caused by the esm module when vite is combined with qiankun is solved, and the front-end integration of vite and qiankun and sand is realized. Box functional integrity.

CN118760469APending Publication Date: 2024-10-11SHENZHEN XUNFANG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410839265.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-10-11

AI Technical Summary

Technical Problem

The existing technology cannot combine vite with qiankun because vite is based on native ES-Module, causing the esm module to access the global scope window object, while the proxy window provided by qiankun's js sandbox cannot be recognized by the esm module, resulting in the sandbox failure.

Method used

By obtaining the entry file of vite, non-module import is introduced, use the @vitejs/plugin-legacy plug-in to package the application file to generate a new build file, and determine whether the browser supports esm mode. If it is not supported, replace the unhijacked ones through SystemJS and polyfill Code to ensure that qiankun's js sandbox function is complete.

Benefits of technology

The front-end integration between vite and qiankun is realized to ensure that qiankun has complete sandbox functions when loading sub-applications built on vite, avoid global pollution, and retain the advantages of vite and achieve the combination of multiple applications at the same time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118760469A_ABST
    Figure CN118760469A_ABST
Patent Text Reader

Abstract

The embodiment of the invention relates to the technical field of front-end development and application, and discloses a project processing method based on vite and qiankun, the processing method comprises the following steps: obtaining an entry file of the vite, the entry file being non-module introduction; packaging the application file through a plug-in provided by the vite to generate a new construction file, wherein the new construction file comprises the converted and degraded codes; according to the new construction file, it is confirmed that the js sandbox function of the qankun is complete, and front-end integration of the vitite and the qankun is achieved. According to the method, the esm problem existing in combination of the viite and the qankun is solved, it is ensured that the viite and the qankun can be accessed in the development environment and the production environment, the sandbox function of the qankun is complete when the qankun is accessed to the viite, and the function of combining multiple applications is achieved on the premise that the advantages of the viite are reserved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of front-end development application technology, and in particular to a project processing method based on vite and qiankun. Background Art

[0002] Qiankun is a micro-frontend implementation library based on single-spa, which can easily and painlessly build a production-ready micro-frontend architecture system; vite is a lighter and faster web application development tool based on native ES-Module for modern browsers; webpack is a static module packaging tool for modern JavaScript applications. Existing technologies can quickly access Qiankun through webpack, but cannot combine Vite with Qiankun.

[0003] The reason why vite and qiankun cannot be combined is that vite and qiankun are not well compatible. vite is a development tool based on native esm. The js sandbox inside qiankun proxies the window object to prevent the global scope from being polluted, but the esm module always has its own independent top-level scope. It accesses the window under the global scope, not the proxy window provided in the qiankun sandbox. Therefore, esm will cause the js sandbox in qiankun to fail. It can be seen that the existing technology cannot achieve the combination of vite and qiankun. Summary of the invention

[0004] The main technical problem solved by the embodiments of the present application is how Qiankun can access Vite while ensuring the integrity of its own sandbox functions.

[0005] To solve the above technical problems, the embodiments of the present application adopt the following technical solutions:

[0006] To solve the above technical problems, in a first aspect, a method for project processing based on vite and qiankun is provided in an embodiment of the present application, and the method comprises:

[0007] Get the entry file of vite, which is a non-module import;

[0008] The plug-in provided by vite is used to package the application files to generate a new build file, which contains the converted and downgraded code.

[0009] According to the new build file, confirm that Qiankun's JS sandbox function is complete, and realize the front-end integration of Vite and Qiankun.

[0010] In some embodiments, the entry file is an HTML entry file of a sub-application under a vite-based construction mechanism.

[0011] It is understandable that the entry file does not include the type field, which is obtained by importing the main.js script file.

[0012] In some embodiments, the plugin is @vitejs / plugin-legacy;

[0013] Plugins are plugins in the Vite ecosystem that provide support for older browsers.

[0014] In some embodiments, the application is packaged and generated into a new build file through a plug-in provided by vite, including:

[0015] When the plug-in is running, it determines whether the current browser supports esm mode;

[0016] If the browser does not support the esm mode, the function implementation that the browser does not support is replaced by a fixed script file to generate a new build file.

[0017] In some embodiments, the fixed script file is vite-legacy-polyfill.

[0018] In some embodiments, the function implementation not supported by the browser is replaced by a fixed script file to generate a new build file, including:

[0019] The entry file is loaded through SystemJS to generate a new build file.

[0020] In some embodiments, the entry file is loaded through SystemJS, including:

[0021] Replace the function implementation in the entry file that is not supported by the browser according to the function implementation in the polyfill;

[0022] Dynamically create script tags;

[0023] Insert the script tag into the head and concatenate it with the css to achieve loading.

[0024] In order to solve the above technical problems, in a second aspect, an electronic device is provided in an embodiment of the present application, including:

[0025] at least one processor; and

[0026] A memory communicatively connected to at least one processor; wherein the memory stores a computer program executable by at least one processor, and the computer program is executed by at least one processor so that the at least one processor can execute the method of the first aspect.

[0027] To solve the above technical problems, in a third aspect, a computer-readable storage medium is provided in an embodiment of the present application, and the computer-readable storage medium stores computer instructions, and the computer instructions are used to implement the method of the first aspect when executed by a processor.

[0028] Beneficial effects of the embodiments of the present application: Different from the prior art, the project processing method based on vite and qiankun provided by the embodiments of the present application includes: obtaining the entry file of vite, which is a non-module introduction; packaging the application file through the plug-in provided by vite to generate a new build file, and the new build file contains the code after conversion and downgrade processing; confirming that the JS sandbox function of qiankun is complete according to the new build file, and realizing the front-end integration of vite and qiankun. By changing the field, the use method of the sub-application entry file built based on vite is changed, so that qiankun can load the above sub-application; using the plug-in provided by vite to replace the code that has not been hijacked, it is ensured that when qiankun uses the above loading method to load the sub-application built based on vite, its sandbox function is complete, and the function of combining multiple applications is realized while retaining the advantages of vite. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0030] Figure 1 This is a flowchart of a project processing method based on vite and qiankun in some embodiments of the present application;

[0031] Figure 2 This is a schematic diagram of the type field of a sub-application entry file in one embodiment of the present application;

[0032] Figure 3 An error diagram showing that Qiankun cannot import an ESM mode file is provided for one embodiment of the present application;

[0033] Figure 4 This is a schematic diagram of the modified sub-application file in some embodiments of the present application. DETAILED DESCRIPTION

[0034] The present application is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present application, but do not limit the present application in any form. It should be noted that, for those of ordinary skill in the art, several variations and improvements can also be made without departing from the concept of the present application. These all belong to the protection scope of the present application.

[0035] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0036] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, all within the scope of protection of the present application. In addition, although the functional module division is performed in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a sequence different from the module division in the device or the flow chart. In addition, the words "first", "second", "third", etc. used herein do not limit the data and execution order, but only distinguish the same items or similar items with basically the same functions and effects.

[0037] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used in this specification and in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.

[0038] In addition, the technical features involved in each embodiment of the present application described below can be combined with each other as long as they do not conflict with each other.

[0039] The following describes the project processing method based on vite and qiankun provided in some embodiments of the present application in combination with the exemplary application and implementation of the project based on vite and qiankun provided in the embodiments of the present application.

[0040] See also Figure 1 , Figure 1 It is a flowchart of a project processing method based on vite and qiankun provided in some embodiments of the present application.

[0041] like Figure 1 As shown, the method S100 may specifically include the following steps:

[0042] S10: Get the entry file of vite, which is a non-module import.

[0043] Vite is a new front-end building tool, mainly composed of a development server and build instructions. The development server provides rich built-in functions and fast module hot update (HMR) based on native esm modules; the build instructions are pre-configured, and can output highly optimized static resources for production environments through Rollup packaging code.

[0044] The entry file is the first file loaded when compiling a project built on Vite. It is located at the outermost layer of the entire project address rather than in the public folder. When loading the entry file, the code is imported as a JavaScript module based on the content of the entry file.

[0045] In some embodiments, the above entry file is an HTML entry file of the qiankun sub-application under the vite-based construction mechanism.

[0046] The core idea of ​​the micro front-end architecture is to split the front-end application into multiple small, self-consistent applications, each of which has its own business logic, UI components, and routing system. These micro front-end applications can be independently developed, tested, and deployed, and combined and work together through an integration mechanism. The micro front-end architecture has the advantages of independence and flexible technology stack.

[0047] Currently, single-spa is a popular and mature micro-frontend solution, which provides a user experience similar to that of single-page applications, is independent of technology stacks and allows multiple applications to coexist, and improves development efficiency through its rich ecosystem. However, in actual projects, the single-spa framework itself does not provide corresponding solutions to common problems such as sub-application loading, isolation of js and css between applications, cleaning up side effects left over from sub-application switching, sub-application state recovery, communication between sub-applications, and sub-application preloading.

[0048] Qiankun provides a new micro-frontend solution to solve the above problems. Based on single-spa, Qiankun has done secondary development to provide a general sub-application loading, communication and preloading solution, and through technical means, it has achieved js and css isolation between applications, side effect cleanup and status response, which can realize a micro-frontend application more simply and quickly.

[0049] Qiankun is divided into application mode and parcle mode. The application mode is based on routing, which divides applications into two categories: base applications and sub-applications. Among them, the base application needs to maintain a routing registry and switch sub-applications according to routing changes; sub-applications are independent applications and need to provide lifecycle methods for base applications to use. Parcle mode is opposite to application mode. It has nothing to do with routing, and sub-applications are switched manually.

[0050] Qiankun uses a new sub-application loading method, namely HTML entry. When using Qiankun, there is no need to define a loading method (loadAppFunc) for the sub-application. After determining the entry of the sub-application, Qiankun obtains the HTML content string corresponding to the sub-application through the fech method according to the URL specified by the entry configuration item, parses the obtained string, collects the sub-application style, js script and installation style, executes the js script to obtain the sub-application life cycle method, and then executes the sub-application mount method.

[0051] In this embodiment, by changing the usage of the entry file of the sub-application built based on vite, qiankun is helped to load the above sub-application.

[0052] In some embodiments, the entry file does not include a type field, and is obtained by importing the main.js script file.

[0053] The esm module obtains the entry file through the URL or file system and parses the above-obtained file. If different parsing methods are used for the same parsed file, the final results will be different. Therefore, before parsing the entry file, it is necessary to confirm whether the above file type is a module. The type field in the html file is used to tell the browser whether to parse this file as a module, such as Figure 2 For example, "type=module" means that the entry file is parsed as a module; "type=nomodule" means that the entry file is parsed as a non-module.

[0054] The application loading solution provided by qiankun is import-html-entry. The above solution allows the html file to be used as the application entry, and then extracts the js and css dependencies from the file through an html parser, and downloads the dependencies through fetch. Therefore, when qiankun loads the sub-application, it obtains the code of the main.js script file according to the entry file and encapsulates it in a function. The above function is executed by the eval function. Because the import statement cannot be used outside the module, it can only be used inside the module, so an error is reported, showing as follows Figure 3 The error message shown. Figure 4 As shown, the type field of the entry file is deleted and imported directly through import. The entry file will not be recognized as a module, so Qiankun can load the sub-application built based on Vite.

[0055] In this embodiment, by deleting the corresponding fields and modifying the import method of the sub-application entry file built based on vite, qiankun and vite can be connected.

[0056] S20: The application files are packaged and generated into a new build file through the plug-in provided by vite. The new build file contains the code after conversion and downgrade processing.

[0057] Thanks to Rollup's excellent plug-in interface design and some additional options unique to Vite, Vite itself provides a wealth of plug-ins and can expand Vite itself through the above plug-ins. Among them, Rollup is a build tool with a built-in packaging function, but the above packaging function cannot meet the construction requirements of more complex projects. Therefore, Rollup has designed a complete plug-in mechanism to separate its core logic from the plug-in logic and introduce plug-in functions as needed.

[0058] It can be seen that vite itself provides a wealth of plug-ins to expand its own functions. For example, during the project development process, there are syntax compatibility issues with older browsers. Therefore, some projects need to adapt the browsers used. The plug-ins provided by vite itself package the application files into new build files to complete the browser adaptation process. The build file is a file produced by compiling or processing the source code.

[0059] The above-mentioned syntax compatibility issues are mainly divided into syntax downgrade issues and polyfill missing issues. There are differences in the syntax supported by different versions of browsers. Usually, low-version browsers do not provide the usage environment, object and array APIs, etc. of the syntax used by high-version browsers. For example, some browsers do not support arrow functions, so they need to be replaced with function(){} syntax during project development; polyfill itself can be translated as a gasket, that is, the browser injects some API implementation code in advance to confirm that the product can use the above API normally. In actual development, low-version browsers may not inject the API implementation code used by high-version browsers in advance.

[0060] It is understandable that there are syntax compatibility issues with lower-version browsers. In the actual development process, the plug-in needs to convert and / or downgrade the code that is incompatible with lower-version browsers, and finally compile and package it into a build file. The build file packaged by the above plug-in is used for browser adaptation.

[0061] In some embodiments, the aforementioned step S20 specifically includes:

[0062] S21: When the plug-in is running, it determines whether the current browser supports the esm mode.

[0063] Among them, esm (ECMAScript modules) is a standard for splitting JavaScript programs into multiple separate modules and importing them on demand. When using esm mode, the browser will build a dependency graph and connect different dependencies according to the different import statements used. The browser or Node determines how to load the code based on the above import statements. Specify an entry point and find other code through the import statement in the file. The browser obtains the target code file by specifying the file path and parses the above file to convert it into a data structure called a module record.

[0064] ES6 implements the module function at the language standard level, aiming to become a universal module solution for browsers and servers. The modular development method can provide code reuse and facilitate code management. Generally speaking, a file is a module. All variables inside the file cannot be obtained from the outside. Different files have their own corresponding scopes and only expose specific variables and functions to the outside. The above module functions are mainly composed of two commands: export and import. The export command is used to specify the external interface of the module, and the import command is used to import the functions of other modules.

[0065] In some embodiments, lower versions of browsers do not support ES6 syntax, such as arrow functions, let, and const, etc. Therefore, there is a problem that older browsers do not support esm mode. When the above-mentioned vite plug-in is running, it is necessary to judge the browser used to confirm whether it supports esm mode.

[0066] S22: If the browser does not support the esm mode, the function implementation that is not supported by the browser is replaced by a fixed script file to generate a new build file.

[0067] Functional implementation means that in a program, a code block consisting of one or more functions realizes part of the required functions. The above code block can be regarded as a whole. Therefore, when the browser used does not support the esm mode, the code that the browser does not support needs to be replaced with the code that the browser can support to complete its function.

[0068] By using fixed script files, the code of lower-version browsers and / or browsers that do not support the esm mode is replaced in units of functions. While retaining the original code functions to the greatest extent, adaptation processing is provided for lower-version browsers and / or browsers that do not support the esm mode.

[0069] In some embodiments, the plug-in is @vitejs / plugin-legacy; the plug-in is a plug-in in the Vite ecosystem, which is used to provide support for older browsers.

[0070] @vitejs / plugin-legacy is a plugin provided by vite, which automatically generates build files compatible with older versions of browsers according to the target browser list specified by the browserslist field in the project configuration. The above build files contain processed and replaced code to ensure normal operation in browsers that do not support the latest JavaScript features.

[0071] The @vitejs / plugin-legacy plugin uses @babel / preset-env and core-js and other basic libraries to perform syntax downgrade and polyfill injection. Through the legacy plugin, Vite will package the products of modern mode and legacy mode respectively, and then insert the two products into the same HTML. The modern product is placed in the script tag of "type=module", and the legacy product is placed in the script tag with nomodule, so that the above products can be compatible with both modern browsers and lower-version browsers that do not support "type=module". The @vitejs / plugin-legacy plugin converts the code through babel and automatically downgrades according to the target browser environment; through the relevant plugin configuration, a polyfill chunk is generated to ensure that the code can run normally in traditional browsers; and @vitejs / plugin-legacy can handle the compatibility of modern browsers and traditional browsers and generate corresponding build files.

[0072] In this embodiment, after using the @vitejs / plugin-legacy plug-in, when a user visits the website, Vite will dynamically load the build file suitable for the user's browser according to the user's browser version. Therefore, @vitejs / plugin-legacy helps developers enjoy faster development and build speeds in modern browsers while providing a good experience for users who are still using old versions of browsers.

[0073] In some embodiments, the fixed script file is vite-legacy-polyfill.

[0074] The above script file contains a line of code "vite polyfill". The code after this line of code is loaded through a specific module loader. When loading, the above module loader replaces the loaded code with a fixed code library to complete the adaptation function of the plug-in.

[0075] In some embodiments, the aforementioned step S22 specifically includes:

[0076] S22a: Load the entry file through SystemJS to generate a new build file.

[0077] SystemJS is a universal module loader that can load and integrate modules in micro-frontend architectures. It supports multiple module formats, such as AMD, CommomJD, and UMD. The module loader has the ability to load modules dynamically, and can load modules on demand at runtime. In addition, SystemJS also creates a separate scope for each module to prevent global pollution between modules. At the same time, SystemJS provides configuration options and a plug-in system that can be flexibly customized and extended according to needs.

[0078] Among them, micro frontend is an architectural style that splits the frontend application into multiple small applications, each of which has its own corresponding development team and technology stack. In the micro frontend architecture, module loading and integration is a key issue.

[0079] SystemJS provides functions such as module loading, on-demand loading, cross-domain loading, module isolation, scope, shared modules and state management for micro-frontend applications. Dynamic module loading means that the application can load modules on demand at runtime. Through the System.import() function, the current application can dynamically load modules of other micro-frontend applications. The above on-demand loading method can reduce the initial loading volume and improve the performance of the application. For different micro-frontend applications deployed in different domains or sub-paths in the micro-frontend architecture, by configuring the map and paths options in System.config(), it is possible to load modules in different domains, that is, cross-domain loading.

[0080] In some embodiments, when the aforementioned script file vite-legacy-polyfill is running, the code after the code "vite polyfill" contained therein is loaded through SystemJS, and the above code includes but is not limited to the code referencing the main.js script file in the entry file and the code of the main.js script file. When SystemJS loads the module, it replaces the loaded code with a fixed code library.

[0081] Each micro-frontend application should have an independent scope to prevent global pollution between modules. SystemJS creates an independent scope for each module to ensure that global variables between modules do not interfere with each other. The above module isolation mechanism helps maintain the stability and reliability of micro-frontend applications.

[0082] In some embodiments, the aforementioned step S22a specifically includes:

[0083] (1) Replace the function implementation in the entry file that is not supported by the browser according to the function implementation in the polyfill.

[0084] Polyfill is also called shim, fill or patch. Its role is to smooth out the API differences between browsers and support new features on old browsers.

[0085] In some embodiments, when SystemJS loads the module, it replaces the code in the entry file and the code in the main.js script file imported by it in units of functions according to the functional implementation in the polyfill, ensuring that lower version browsers and / or browsers that do not support esm mode can load the sub-application normally.

[0086] Polyfill dynamically inserts patch code based on the characteristics of the browser, and returns different codes based on the browser user-agent, which effectively solves the patch redundancy problem caused by dynamic patch code.

[0087] (2) Dynamically create script tags.

[0088] The srcipt tag is used to embed client-side scripts, that is, to load a JavaScript script from the server and execute it in the current page. Its elements contain script statements or point to external script files through the src attribute.

[0089] By default, script tags are loaded synchronously. When an HTML page is loading, if it encounters a script tag, it will interrupt the loading of the HTML page, initiate a request to the server based on the corresponding src address in the script tag, load the corresponding JavaScript script and execute it. When the above script is executed, the HTML page will continue to load.

[0090] A common usage of the script tag is to place all its elements in the head element. Therefore, during the program running process, it is necessary to wait for all the js codes to be downloaded, parsed and executed before the content of the web page can be presented. For pages that require more js codes, the above usage will cause a significant delay in the browser's presentation of the page.

[0091] Dynamically create script tags through the windows.onload method to ensure that the script tags are inserted into the DOM after the page is loaded, realizing asynchronous loading and ensuring that the program will not block the parsing of the DOM tree and the execution of other scripts during the loading process.

[0092] (3) Insert the script tag into the head and concatenate it with the CSS.

[0093] The head tag is an important part of the HTML document. It is located inside the HTML tag and is used to define the header information and metadata of the document. The elements within the head tag are usually not directly presented on the page, but provide various information and configurations of the document.

[0094] CSS (Cascading Style Sheets) is a language used to describe the formatting and display of information on a web page. Its main function is to control the visual presentation of a web page, including style structures such as fonts, colors, and layouts. CSS is widely used and can be used to control the style of almost all visible elements on a web page, such as text fonts, sizes, colors, or element positions, sizes, and various interactive effects. CSS styles can be written directly in HTML documents or stored separately in style sheet files and shared by multiple pages. In either case, the style sheet contains rules for applying styles to elements of a specified type.

[0095] In some embodiments, when SystemJS loads the entry file, it dynamically creates a script tag and puts it into the head tag to splice with CSS. It ensures that the program will not block the parsing of the DOM tree and the execution of other scripts during the loading process by dynamically creating the scrip tag, and CSS realizes the separation of document content and presentation, which not only improves the maintainability of the web page, but also makes the style more flexible and diverse.

[0096] S30: Confirm that Qiankun's JS sandbox function is complete based on the new build file, and realize the front-end integration of Vite and Qiankun.

[0097] Sandbox is a security mechanism used to strictly control access to resources. It creates an independent operating environment in the program, puts untrustworthy, destructive and / or unidentifiable malicious programs into the above operating environment, and isolates the impact on the program.

[0098] The code in plyfill is hijacked by qiankun. Therefore, in some embodiments, the non-hijacked code is replaced by polyfill in units of functions. The replaced code, i.e., the code in polyfill, is hijacked by qiankun. The above process ensures the integrity of the qiankun sandbox function and avoids global pollution caused by the introduction of non-hijacked code.

[0099] Different from the prior art, the beneficial effect of the embodiment of the present application is: by removing the type field in the entry file of the sub-application built based on vite, changing the usage of the above entry file, avoiding Qiankun from treating it as a module introduction when loading the entry file of the sub-application, and realizing Qiankun successfully loading the sub-application built based on vite. In addition, the application files are packaged using the plug-in @vitejs / plugin-legacy provided by vite. If the browser used does not support the esm mode, the code that is not hijacked by Qiankun is replaced in units of functions through the SystemJS module loader, and replaced with the code hijacked by Qiankun in the polyfill to ensure that the sandbox function of Qiankun is complete. The above method solves the esm problem existing in the combination of vite and Qiankun, while ensuring the integrity of the sandbox function when Qiankun is connected to the sub-application built based on vite, and ensures the security of the combination of Qiankun and Vite while retaining the advantages of vite.

[0100] It should be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0101] Through the description of the above implementation methods, ordinary technicians in this field can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, it can also be implemented by hardware. Ordinary technicians in this field can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing related hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0102] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as described above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A project processing method based on Vite and Qiankun, characterized in that: include: Get the entry file of the vite, which is a non-module import; The application file is packaged using the plug-in provided by Vite to generate a new build file, wherein the new build file contains the converted and downgraded code; According to the new build file, the JS sandbox function of Qiankun is confirmed to be complete, and the front-end integration of Vite and Qiankun is realized.

2. The method according to claim 1, characterized in that The entry file is the HTML entry file of the sub-application based on the construction mechanism of Vite.

3. The method according to claim 1, characterized in that The entry file does not include the type field and is obtained by importing the main.js script file.

4. The method according to claim 1, wherein The plug-in is @vitejs / plugin-legacy; The plug-in is a plug-in in the Vite ecosystem and is used to provide support for older browsers.

5. The method according to claim 1, wherein The plug-in provided by Vite is used to package the application to generate a new build file, including: When the plug-in is running, it determines whether the current browser supports ESM mode; If the browser does not support the esm mode, the function implementation that the browser does not support is replaced by a fixed script file to generate the new build file.

6. The method according to claim 5, characterized in that The fixed script file is vite-legacy-polyfill.

7. The method according to claim 5, characterized in that Then, the functions not supported by the browser are replaced by fixed script files to generate a new build file, including: The entry file is loaded through SystemJS to generate the new build file.

8. The method according to claim 7, characterized in that The loading of the entry file through SystemJS includes: Replace the function implementation in the entry file that is not supported by the browser according to the function implementation in the polyfill; Dynamically create script tags; Insert the script tag into the head and splice it with the css to achieve the loading.

9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and A memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor so as to enable the at least one processor to execute the project processing method based on Vite and Qiankun according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the project processing method of Vite and Qiankun according to any one of claims 1 to 8 when executed.