Application packaging and building methods, devices, electronic devices, and storage media

CN122569929APending Publication Date: 2026-08-14GUANGZHOU TENCENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-13
Publication Date
2026-08-14

AI Technical Summary

Technical Problem

[0003]鉴于上述问题,本申请实施例提出了一种应用的打包构建方法、装置、电子设备及存储介质,以解决相关技术中应用打包构建用时较长的问题

Benefits of technology

[0018]在本申请中,按照目标应用的运行环境的数量,将目标应用的打包构建任务拆分成多个子打包构建任务,一个子打包构建任务用于将目标应用在一个运行环境下的前端源文件进行打包构建,并且,并行执行所述N个子打包构建任务中的至少两个子打包构建任务,这样,由于同一时间并行执行至少两个子打包构建任务,相较于相关技术中,将目标应用的打包构建任务串行执行,大幅缩短了目标应用的打包构建用时。而且,由于目标应用在不同运行环境下的源代码之间是相互独立的,因此,将多个子打包构建任务并行执行,并不会影响目标应用的整体的打包构建结果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122569929A_ABST
    Figure CN122569929A_ABST
Patent Text Reader

Abstract

This application relates to the field of computer technology and discloses a method, apparatus, electronic device, and storage medium for packaging and building an application. The method includes: obtaining runtime environment indication information of a target application; the runtime environment indication information indicates N runtime environments of the target application; according to the N runtime environments of the target application, splitting the packaging and building task of the target application into N sub-packaging and building tasks, and generating task information for the N sub-packaging and building tasks; according to the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks are completed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain a packaged file in which the target application runs in the runtime environment corresponding to the sub-packaging and building task. This application can shorten the packaging and building time of the application.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, electronic device, and storage medium for packaging and building applications. Background Technology

[0002] After developers complete the application's source code development, the source code needs to be packaged and built to generate code that can run efficiently in a production environment. In related technologies, if the application's functionality is complex and the amount of source code is large, the packaging and building process takes a considerable amount of time. Therefore, how to shorten the packaging and building time is a pressing technical problem that needs to be solved in related technologies. Summary of the Invention

[0003] In view of the above problems, this application proposes an application packaging and building method, apparatus, electronic device and storage medium to solve the problem of long application packaging and building time in related technologies.

[0004] According to one aspect of the embodiments of this application, a method for packaging and building an application is provided, comprising: obtaining runtime environment indication information of a target application; the runtime environment indication information is used to indicate N runtime environments of the target application; N is an integer greater than 1; according to the N runtime environments of the target application, splitting the packaging and building task of the target application into N sub-packaging and building tasks, and generating task information for the N sub-packaging and building tasks; wherein, the task information of one sub-packaging and building task includes the source file address of the front-end source file of the target application in one runtime environment; according to the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks are executed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain a packaged file in which the target application runs in the runtime environment corresponding to the sub-packaging and building task.

[0005] According to one aspect of the embodiments of this application, an application packaging and building apparatus is provided, comprising: an acquisition module, configured to acquire runtime environment indication information of a target application; the runtime environment indication information is used to indicate N runtime environments of the target application; N is an integer greater than 1; a task splitting module, configured to split the packaging and building task of the target application into N sub-packaging and building tasks according to the N runtime environments of the target application, and generate task information for the N sub-packaging and building tasks; wherein, the task information of one sub-packaging and building task includes the source file address of the front-end source file of the target application in one runtime environment; and a parallel execution module, configured to execute at least two of the N sub-packaging and building tasks in parallel according to the corresponding task information, until all N sub-packaging and building tasks are executed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain a packaged file in which the target application runs in the runtime environment corresponding to the sub-packaging and building task.

[0006] In some embodiments, the task information further includes the packaging and building time of the sub-packaging and building task; the application's packaging and building device further includes: a process creation module, used to create M processes; 2≤M≤N, where M is an integer; a process allocation module, used to allocate processes among the M processes to the N sub-packaging and building tasks according to the packaging and building time of each sub-packaging and building task, and determine at least one sub-packaging and building task that each of the M processes is responsible for executing; wherein the time difference between the total packaging and building time of at least one sub-packaging and building task executed by any two processes does not exceed a first threshold; a parallel execution module, including: a parallel running unit, used to run the M processes in parallel, so that each process packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for according to the task information of the sub-packaging and building task it is responsible for, to obtain the corresponding packaged file.

[0007] In some embodiments, M < N, the process allocation module includes: a grouping unit, configured to group the N sub-packaging build tasks into K groups according to the terminal platforms corresponding to each of the N running environments; wherein the running environments corresponding to the sub-packaging build tasks in the same group are located on the same terminal platform, and the running environments corresponding to the sub-packaging build tasks in different groups are located on different terminal platforms, and 2 ≤ K < N; a first allocation unit, configured to, if K ≤ M, allocate at least one sub-packaging build task in the same group whose cumulative packaging build time and reference duration do not exceed a second threshold to the same process; the second threshold does not exceed the first threshold; a second allocation unit, configured to allocate the remaining sub-packaging build tasks in the K groups to the remaining processes in the M processes that have not been allocated sub-packaging build tasks, based on the packaging build time of the remaining sub-packaging build tasks in the K groups; wherein the duration difference between the total packaging build time corresponding to one of the remaining processes and the reference duration does not exceed the second threshold.

[0008] In some embodiments, the process allocation module further includes: a third allocation unit, configured to, if K > M, allocate the sub-packaging and building tasks located in the same group among the M groups with the longest total packaging and building time in the K groups to one of the M processes; and a fourth allocation unit, configured to allocate the packaging and building time of the sub-building tasks in the other groups among the K groups to each of the M processes, so that the time difference between the total packaging and building time of any two processes does not exceed a first threshold.

[0009] In some embodiments, the application's packaging and building apparatus further includes: a sorting module, configured to sort at least one sub-build task executed by the same process, and determine the task execution order corresponding to each process, wherein the sub-packaging and building tasks corresponding to multiple runtime environments located on the same terminal platform have consecutive sequence numbers in the task execution order of the corresponding processes; and a parallel running unit, configured to: run the M processes in parallel, so that each process, according to the task information of the sub-packaging and building task it is responsible for, sequentially packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for, according to the corresponding task execution order, to obtain the corresponding packaged file.

[0010] In some embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; the application packaging and building device further includes: a first deletion module, used to delete the second source file address of the unchanged front-end source file from the task information of each sub-packaging and building task, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application in the corresponding running environment.

[0011] In other embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; correspondingly, the application packaging and building device further includes: a dependency determination module, used to determine at least one dependent business function that has a dependency relationship with the target business function to which the incremental front-end source file belongs, based on the dependency relationship between different business functions in the target application; and a second deletion module, used to delete the second source file addresses of other unchanged front-end source files (excluding those representing the at least one dependent business function) from the task information of each sub-packaging and building task, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address and the unchanged front-end source file pointed to by the second source file address in the corresponding task information, representing the at least one dependent business function, are packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0012] In some embodiments, the parallel execution module is configured to: execute each of the sub-packaging and building tasks using a packaging and building tool according to the following process: obtaining the corresponding front-end source file according to the source file address in the task information of the sub-packaging and building task; parsing the front-end source file to obtain a parsing result; compiling the front-end source file using a loader in the packaging and building tool to obtain a compilation result; and generating a package file for the target application in the runtime environment corresponding to the sub-packaging and building task based on the compilation result and the parsing result.

[0013] In some embodiments, the loader includes a first loader for compiling logic files in the front-end source files; the application packaging and building apparatus further includes: an instruction acquisition module for acquiring a loader replacement instruction; and a replacement module for replacing the default loader in the packaging and building tool for compiling logic files with the first loader in response to the loader replacement instruction; the first loader has a faster compilation speed than the default loader.

[0014] In some embodiments, the method is executed by an electronic device, and the process creation module is used to: obtain the number of cores of the electronic device; and use the number of cores as M to create M processes.

[0015] According to one aspect of the embodiments of this application, an electronic device is provided, including: a processor; and a memory storing computer-readable instructions, which, when executed by the processor, implement the above-described application packaging and building method.

[0016] According to one aspect of the embodiments of this application, a computer-readable storage medium is provided that stores computer-readable instructions thereon, which, when executed by a processor, implement the above-described application packaging and building method.

[0017] According to one aspect of the embodiments of this application, a computer program product is provided, including computer instructions that, when executed by a processor, implement the packaging and building method of the application described above.

[0018] In this application, the target application's packaging and build task is divided into multiple sub-packaging and build tasks according to the number of runtime environments of the target application. Each sub-packaging and build task packages and builds the front-end source files of the target application in one runtime environment. Furthermore, at least two of the N sub-packaging and build tasks are executed in parallel. This significantly reduces the packaging and build time of the target application compared to the serial execution of the target application's packaging and build tasks in related technologies, as at least two sub-packaging and build tasks are executed concurrently at the same time. Moreover, since the source code of the target application in different runtime environments is independent of each other, executing multiple sub-packaging and build tasks in parallel does not affect the overall packaging and build result of the target application. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.

[0020] Figure 1 This is a schematic diagram illustrating an application scenario of this application according to an embodiment of this application.

[0021] Figure 2 This is a flowchart illustrating a packaging and building method for an application according to an embodiment of this application.

[0022] Figure 3 This example illustrates a schematic diagram of multiple application environments for an XX online document application.

[0023] Figure 4 This is a flowchart illustrating the execution of various sub-packaging and building tasks according to an embodiment of this application.

[0024] Figure 5 An example diagram illustrates the processing before and after replacement in Webpack.

[0025] Figure 6 An example is shown in the chart illustrating the time taken to build the package before and after replacing the loader.

[0026] Figure 7A This is a flowchart illustrating a packaging and building method for an application according to another embodiment of this application.

[0027] Figure 7B This is a schematic diagram illustrating the sub-build tasks assigned to each process according to an embodiment of this application.

[0028] Figure 8 This is a flowchart illustrating a packaging and building method for an application according to another embodiment of this application.

[0029] Figure 9 This is a flowchart illustrating a packaging and building method for an application according to another embodiment of this application.

[0030] Figure 10 This is a block diagram of a packaging and building apparatus for an application according to an embodiment of this application.

[0031] Figure 11 A schematic diagram of the structure of a computer system suitable for implementing the electronic device of the present application is shown. Detailed Implementation

[0032] The embodiments of this application are described in detail below. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain this application, and should not be construed as limiting this application.

[0033] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are merely some embodiments of the present application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without creative effort are within the scope of protection of the present application.

[0034] In the following description, the terms "first" and "second" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first" and "second" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0035] In this document, "multiple" refers to two or more. "And / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following associated objects are in an "or" relationship. In the following description, references to "some embodiments or some embodiment methods" describe a subset of all possible embodiments. However, it is understood that "some embodiments" can be the same subset or different subsets of all possible embodiments and can be combined with each other without conflict.

[0036] The following is an explanation of the terms used in this application:

[0037] Packaging and building refers to the process of optimizing, compiling, and packaging front-end source code (including HTML (HyperText Markup Language), CSS (Cascading Style Sheets), JavaScript, etc.) to ultimately generate code that can run efficiently in a production environment. The production environment includes, for example, the runtime environment under various operating systems.

[0038] As applications become increasingly feature-rich and larger, they are packaged and built before being distributed for users to download and install. Currently, application packaging typically involves bundling the application's code into a single bundle file. In related technologies, the packaging and building of the application's source code is usually done in a single process, which can be time-consuming if the application's source code is large. Therefore, the solution proposed in this application is presented.

[0039] Figure 1This is a schematic diagram illustrating an application scenario of this application according to an embodiment of this application. For example... Figure 1 As shown, this application scenario includes a terminal 110, a first server 120, and a second server 130. The terminal 110 and the first server 120 are connected via a wired or wireless network, and the first server 120 and the second server 130 are also connected via a wired or wireless network. The first server 120 is responsible for packaging and building the source code, and the second server 130 is used to distribute the packaged application files.

[0040] like Figure 1 As shown, a user can initiate a packaging and building request for a target application through the display interface of terminal 110. After receiving the packaging and building request for the target application, the first server 120 can perform packaging and building according to the method of this application. Specifically, the first server 120 can obtain the runtime environment indication information of the target application; the runtime environment indication information is used to indicate N runtime environments of the target application; N is an integer greater than 1; then, according to the N runtime environments of the target application, the packaging and building task of the target application is split into N sub-packaging and building tasks, and task information of N sub-packaging and building tasks is generated; wherein, the task information of a sub-packaging and building task includes the source file address of the front-end source file of the target application in one runtime environment; subsequently, according to the corresponding task information, at least two of the N sub-packaging and building tasks are executed in parallel until all N sub-packaging and building tasks are executed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application running in the runtime environment corresponding to the sub-packaging and building task.

[0041] After obtaining the packaged files corresponding to the target application in N different operating environments from the first server 120, the second server 130 can distribute the packaged files corresponding to the target application in N different operating environments for users to download.

[0042] Terminal 110 can be a smartphone, tablet, laptop, desktop computer, smart TV, vehicle terminal, or other terminal. First server 120 and second server 120 can be independent physical servers, server clusters or distributed systems composed of multiple physical servers, or cloud servers providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.

[0043] The implementation details of the technical solutions in the embodiments of this application are described in detail below:

[0044] Figure 2 This is a flowchart illustrating a packaging and building method for an application according to an embodiment of this application. This method can be executed by an electronic device with processing capabilities, such as a server, and is not specifically limited thereto. (Refer to...) Figure 2 As shown, the method includes at least steps 210 to 230, which are described in detail below:

[0045] Step 210: Obtain the runtime environment indication information of the target application; the runtime environment indication information is used to indicate the N runtime environments of the target application; N is an integer greater than 1.

[0046] The target application refers to the application to be packaged and built. There are no restrictions on the type of application; it can be an online document application, instant messaging application, game application, shopping application, video application, live streaming application, etc.

[0047] The object being packaged and built is the source code developed by software developers for the target application. Developers typically develop code on a code development platform, and after completing the code development, they initiate a packaging and build process. Therefore, in some embodiments, the runtime environment indication information of the target application can be obtained in response to a packaging and build command submitted on the code development platform for the target application.

[0048] An application's runtime environment refers to the software and hardware environment required for the application's program to execute. It provides the resources and support needed for the application to run, including the operating system, compiler, interpreter, library files, device drivers, etc. If an application's client can run independently, the environments provided by different operating systems on different terminal platforms are considered different runtime environments. For example, the environment provided by the Android system on a smartphone is considered one runtime environment, while the environment provided by the iOS system on a smartphone is considered another. Here, "smartphone" is one terminal platform, which also includes tablets, computers, etc. If an application runs as a sub-application of a third-party application, then the application running on a single operating system on a single terminal platform (i.e., the third-party application acting as the carrier) is considered to be running in one runtime environment. If at least one of the terminal platform, operating system, or carrier software is different, they are considered different runtime environments.

[0049] Figure 3 The illustration shows a schematic diagram of multiple application environments for an online document application, which can use third-party applications as its runtime environment. These third-party applications include, for example... Figure 3 Application A and browser in the middle, Figure 3This demonstrates the different operating environments of the XX online document application on three different terminal platforms (i.e., desktop computer, tablet computer, and mobile phone), such as a low-version browser version on the desktop computer, a high-version version of application A on the desktop computer, and a test version of application A. Figure 3 The document shows a total of 18 application environments for the XX online document application. Of course, for other applications, the corresponding runtime environments may include... Figure 3 Less or more operating environments Figure 3 The operating environment shown is merely an example and should not be construed as limiting the scope of this application.

[0050] The granularity of the application's runtime environment can be set according to actual needs. For example, it can be divided by terminal platform (e.g., desktop computer, tablet computer, mobile phone), with each terminal platform considered a separate runtime environment. In this case, it's equivalent to... Figure 3 The six runtime environments subdivided under each terminal platform are considered as one runtime environment. Alternatively, it can be divided at the granularity of the operating system on the terminal platform, meaning that one operating system on a terminal platform is considered one runtime environment.

[0051] Considering that the target application's source code is developed as a project on a code development platform, the software project containing the target application on the platform will configure basic information about the target application, such as its runtime environment and version. Therefore, the runtime environment information of the target application can be obtained from the software project containing the target application on the code development platform. It can be understood that the N runtime environments of the target application refer to the runtime environments involved in the source code of the target application currently being packaged and built.

[0052] Step 220: Based on the N runtime environments of the target application, the packaging and building task of the target application is split into N sub-packaging and building tasks, and task information for the N sub-packaging and building tasks is generated; wherein, the task information of a sub-packaging and building task includes the source file address of the front-end source file of the target application in one runtime environment.

[0053] A sub-build task is used to package and build the front-end source files of the target application in a runtime environment, resulting in a packaged file of the target application in that runtime environment. This packaged file can be the code files that run in the corresponding runtime environment.

[0054] In addition to the source file addresses of the front-end source files, the task information for a sub-build task includes the file information of the front-end source files, the build time for packaging the front-end source files, and the storage address for the corresponding packaged files. The file information of the front-end source files can include the file types of each file within the front-end source files. The code in the front-end source files is the source code developed by developers for a target application running in a specific environment.

[0055] The code development platform maintains the file addresses of each front-end source file for the target application, as well as the corresponding description information for each front-end source file. The description information describes the applicable runtime environment for the corresponding front-end source file. Therefore, based on the runtime environment corresponding to the sub-packaging build task and the description information for each front-end source file, the source code file applicable to the runtime environment corresponding to the sub-packaging build task can be determined, and the file address of the determined source code file can be obtained as the source file address of the front-end source file of the target application in a runtime environment.

[0056] The front-end source files include style files and logic files. The source code in the style files describes the style information of the target application's interface in the corresponding runtime environment; the source code in the logic files describes the processing logic related to user interaction on the target application's interface in the corresponding runtime environment.

[0057] The package file storage address in the task information of a sub-package build task refers to the storage address specified for the output (package file) of that sub-package build task. The build time for the front-end source files refers to the estimated time required to package and build the front-end source files.

[0058] The front-end source files of the target application in a runtime environment include the complete front-end source code of the target application in that runtime environment, including all the source code required for the target application to run in that runtime environment. In some embodiments, if the packaging and build task initiated for the target application is not the first packaging and build task initiated for the target application, in this case, the front-end source files of the target application in each runtime environment may involve unchanged source code and changed incremental source code. That is, the front-end source files of the target application in a runtime environment include incremental front-end source files and unchanged front-end source files. The source code in the incremental front-end source files is the changed source code, and the code in the unchanged front-end source files is the code that has not changed compared to the previous version.

[0059] Step 230: Based on the corresponding task information, execute at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks are completed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain the packaged file that the target application runs in the runtime environment corresponding to the sub-packaging and building task.

[0060] In other words, at least two sub-packaging build tasks are executed in parallel at the same time. This means that if the number of sub-packaging build tasks executed in parallel at the same time is less than N, some of the sub-packaging build tasks are executed sequentially. If the number of sub-packaging build tasks executed in parallel at the same time is equal to N, then N sub-packaging build tasks are executed in parallel.

[0061] During the execution of a sub-build task, the front-end source files of the target application in the corresponding runtime environment can be obtained from the source file addresses provided in the task information. These front-end source files are then packaged and built to obtain the packaged file of the target application running in the runtime environment corresponding to the sub-build task. This packaging and building can be performed using a packaging and building tool. Examples of such tools include Webpack, Rollup, Vite, and Maven, but no specific limitation is specified here.

[0062] In some embodiments, it can be done as follows Figure 4 The process shown executes each sub-packaging and build task, including:

[0063] Step 410: Obtain the corresponding front-end source file according to the source file address in the task information of the sub-packaging build task. It's understandable that before executing the sub-packaging build task, it's necessary to load the dependency libraries, software libraries, etc., required during the packaging build process into the content.

[0064] Step 420: Parse the front-end source file to obtain the parsing result.

[0065] The build tool can parse the front-end source files and recursively resolve the dependencies between different sub-files in the front-end source files. The parsing result executes the dependencies between different sub-files in the front-end source files.

[0066] Step 430: Compile the front-end source files using the loader in the packaging and build tool to obtain the compilation result.

[0067] For different types of code modules in the front-end source files, corresponding loader can be used for compilation. The compilation result includes the sub-compilation results of each sub-file in the front-end source file. By compiling the front-end source files, the source code in the front-end source files can be compiled into executable code that can run in the corresponding runtime environment.

[0068] The build tool provides multiple loaders for compiling different types of files. These loaders can be the default loader used by the build tool, or other loaders compatible with it.

[0069] Taking Webpack as an example, the default loaders provided by Webpack include the less loader and the tsc loader. The less loader is used to compile less (Leaneer style Sheets) files into CSS files; the tsc loader is used to compile TypeScript code files into JavaScript files (also known as js or ts files) so that they can run in the browser.

[0070] Step 440: Based on the compilation and parsing results, generate the package file for the target application in the runtime environment corresponding to the sub-packaging build task.

[0071] After compilation, the compiled results can be further processed using plugins in the build tool, such as code compression, file merging, and resource optimization. For example, taking Webpack as the build tool, plugins in Webpack, such as the Html plugin, simplify the creation and management of HTML files. The Html plugin can automatically import resources such as JavaScript and CSS into HTML files based on a specified template or default template.

[0072] Subsequently, the build tool can combine the parsing results and the compilation results processed by the plugin to package the relevant resources together into a bundle file, which is a static resource file that can be loaded and executed in the browser.

[0073] After obtaining the packaged file of the target application in the runtime environment corresponding to a sub-packaged build task, the packaging and build tool can output the packaged file to the location indicated by the packaged file address in the corresponding task information, and then distribute the packaged file to various terminals.

[0074] In some embodiments, the loader in step 440 above includes a first loader for compiling logic files in the front-end source files; the first loader may not be the default loader of the packaging build tool. Correspondingly, before step 430, the method further includes: obtaining a loader replacement instruction; in response to the loader replacement instruction, replacing the default loader in the packaging build tool for compiling logic files with the first loader; the compilation speed of the first loader is faster than that of the default loader.

[0075] Understandably, this first loader is the loader used by the build tool to compile logic files. Since front-end source files are usually written in TypeScript, compiling TypeScript code into JavaScript code that runs in the runtime environment takes a long time during the build process. Therefore, replacing the default loader in the build tool that is used to compile logic files (TypeScript code files) with the faster first loader can shorten the time of individual sub-build tasks and also shorten the overall build time of the target application.

[0076] Taking Webpack as an example, the default loader used by Webpack to compile logic files is the tsc loader. The tsc loader is written in JavaScript, which is user-friendly for web developers. However, JavaScript is not a high-performance language, and its performance is inferior to low-level languages ​​like Rust and C++. Therefore, considering that the swc loader is based on swc (Speedy Web Compiler) and can be called by Webpack, and that the swc loader is a high-performance JavaScript and TypeScript compiler written in Rust, and that the SWC build library called by the swc loader is also written in high-performance Rust, using the swc loader to compile logic files can improve the compilation speed of logic files and shorten the bundling and build time. Experiments have shown that using the SWC build library called by the swc loader to compile logic files is more than 5 times faster than using the tsc loader to call the TSC build library.

[0077] Therefore, the swc loader can be used as the first loader, replacing the default tsc loader in Webpack with the swc loader. Figure 5 An example diagram illustrates the processing before and after the replacement in Webpack, such as... Figure 5As shown, before the replacement, Webpack used its less loader to compile CSS and Less files, its html plugin to process some code modules in the front-end source files to obtain HTML files, and its tsc loader to compile logic files to obtain JS and TypeScript files. After the replacement, the functionality of the less loader and html plugin remains unchanged; the difference is that the swc loader is now used to compile logic files to obtain JS and TypeScript files. Figure 6 An example chart shows the time taken to build and bundle the XX online document before and after replacing the tsc loader with the swc loader in Webpack. Figure 6 As can be seen, replacing the tsc loader in Webpack with the swc loader reduced the overall build time by about 30%.

[0078] In some embodiments, M processes can be created and run in parallel to execute M sub-packaging build tasks out of N sub-packaging build tasks simultaneously, where 2 ≤ M ≤ N, and M is an integer. A process executes one sub-packaging build task at a given time. After a process completes one sub-packaging build task, it retrieves the remaining unexecuted sub-packaging build tasks from the N sub-packaging build tasks and continues execution until all N sub-packaging build tasks have been completed.

[0079] In some embodiments, N processes can be created based on the total number of sub-package build tasks (i.e., N), so that each process is responsible for executing one sub-package build task.

[0080] In some embodiments, the total number of sub-package build tasks, N, can be distributed among M processes to ensure that the difference in the total number of sub-package build tasks executed by different processes does not exceed 1. For example, if there are a total of 8 sub-package build tasks and 8 processes, one sub-package build task can be assigned to each process; if there are a total of 8 sub-package build tasks and 4 processes, two sub-package build tasks can be assigned to each process; and if there are a total of 9 sub-package build tasks and 4 processes, one process can be assigned to execute 3 sub-package build tasks, and the other 3 processes can each be assigned 2 sub-package build tasks.

[0081] In some embodiments, the task information also includes the packaging and building time of the sub-packaging and building task; such as Figure 7A As shown, prior to step 230, the method further includes:

[0082] Step 710: Create M processes; 2≤M≤N, where M is an integer.

[0083] In some embodiments, M processes can be created, with the number of cores (M) of the electronic device currently responsible for the packaging and building task of the target application. The number of cores refers to the number of cores in the central processing unit (CPU) of the electronic device. The electronic device can be a cloud server or similar device. Of course, in other embodiments, M can be less than the number of cores in the electronic device. The number of processes created can be determined based on the current load of the electronic device to avoid overloading the device during the parallel execution of sub-packaging and building tasks.

[0084] Step 720: Based on the packaging and building time of each sub-packaging and building task, allocate processes to N sub-packaging and building tasks in M ​​processes, and determine at least one sub-packaging and building task that each process in M ​​processes is responsible for executing; wherein, the difference in the total packaging and building time of at least one sub-packaging and building task executed by any two processes does not exceed the first threshold.

[0085] Since the difference in total packaging and building time between any two processes for at least one sub-packaging and building task does not exceed the first threshold, it can be ensured that the total runtime difference between different processes among the M processes is small.

[0086] In some embodiments, the build times of the N sub-build tasks can be summed to obtain a first total build time. Then, the first total build time is divided by M, and the result is used as a reference time. Next, based on the reference time and the build times of each sub-build task, the N sub-build tasks are divided into M reference groups. The time difference between the total build time of all sub-build tasks within a reference group and the reference time does not exceed a second threshold, and the second threshold does not exceed a first threshold. Based on this, one process is responsible for executing all sub-build tasks within a reference group, and different processes are responsible for executing different reference groups.

[0087] Figure 7B This is a schematic diagram illustrating the sub-build tasks allocated to each process according to an embodiment of this application. Figure 7B The example shows two sub-packaging build tasks assigned to processes 1 through 4 respectively.

[0088] based on Figure 7A In the corresponding embodiment, step 230 includes: step 231, running M processes in parallel, so that each process packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for according to the task information of the sub-packaging and building task it is responsible for, and obtains the corresponding packaged file.

[0089] In this application, the packaging and building task of the target application is divided into multiple sub-packaging and building tasks according to the number of multiple runtime environments of the target application. Each sub-packaging and building task is used to package and build the front-end source files of the target application in one runtime environment. Furthermore, at least two of the N sub-packaging and building tasks are executed in parallel. This significantly reduces the packaging and building time of the target application compared to the serial execution of the packaging and building tasks in related technologies, as at least two sub-packaging and building tasks are executed in parallel at the same time. Moreover, since the source code of the target application is independent of each other in different runtime environments, executing multiple sub-packaging and building tasks in parallel does not affect the overall packaging and building result of the target application.

[0090] The solution presented in this application is particularly suitable for situations where the source code to be packaged and built involves the same application running in multiple environments. For example, the packaging and building process for an online document application requires compiling and packaging resources such as JavaScript, HTML, CSS, and images from the source code, then assembling different resource packages for different runtime environments, and pushing them to the distribution platform for users to download and use. By splitting the packaging and building task of the target application and executing at least two sub-packaging and building tasks in parallel simultaneously, the packaging and building speed is significantly improved, and the time spent on code modification, testing, product testing, and deployment is greatly reduced, accelerating the iteration speed of the target application. Furthermore, by splitting and executing the packaging and building tasks in parallel, the scalability of the packaging and building process is enhanced; for example, the number of sub-packaging and building tasks executed in parallel can be configured as needed.

[0091] In some embodiments, M < N, such as Figure 8 As shown, step 720 includes the following steps 810-830:

[0092] Step 810: Based on the terminal platforms corresponding to each of the N running environments, group the N sub-packaging and building tasks into K groups; wherein the running environments corresponding to the sub-packaging and building tasks in the same group are located on the same terminal platform, and the running environments corresponding to the sub-packaging and building tasks in different groups are located on different terminal platforms, 2≤K<N.

[0093] Terminal platforms include, for example, smartphones, tablets, and desktop computers, as mentioned above. For instance, for... Figure 3 The multiple runtime environments shown can group the sub-packaging and build tasks corresponding to the 6 runtime environments running on a computer desktop into one group, the sub-packaging and build tasks corresponding to the 6 runtime environments running on a tablet into one group, and the sub-packaging and build tasks corresponding to the 6 runtime environments running on a smartphone into one group.

[0094] Step 820: If K≤M, at least one sub-packaging and building task located in the same group whose cumulative packaging and building time difference with the reference time does not exceed the second threshold is assigned to the same process; the second threshold does not exceed the first threshold.

[0095] When K ≤ M, it indicates that the number of processes is insufficient to allocate all sub-build packaging tasks within a group to a single process. Therefore, based on the packaging build time of each sub-package build task within the same group and a reference time, at least one sub-package build task within a group whose cumulative packaging build time and the difference between the reference time and the reference time do not exceed a second threshold can be allocated to the same process. The reference time can be equal to the result of dividing the first total time mentioned above by M. In this way, it can be prioritized that sub-package build tasks corresponding to multiple runtime environments on the same terminal platform are allocated to a single process.

[0096] For example, if a group A1 includes sub-packaging build task 1, sub-packaging build task 2, sub-packaging build task 3 and sub-packaging build task 4, and if it is determined that the time difference between the cumulative packaging build time of sub-packaging build task 1, sub-packaging build task 2 and sub-packaging build task 3 and the reference time does not exceed the second threshold, sub-packaging build task 1, sub-packaging build task 2 and sub-packaging build task 3 can be assigned to the same process.

[0097] In some embodiments, if K = M and the time difference between the total packaging and building times of different groups does not exceed a first threshold, all sub-packaging and building tasks in a group can be assigned to the same process.

[0098] Step 830: Based on the packaging and building time of the remaining sub-packaging and building tasks of the unassigned processes in the K groups, allocate the remaining sub-packaging and building tasks of the unassigned processes in the M processes; wherein, the time difference between the total packaging and building time corresponding to a remaining process and the reference time does not exceed the second threshold.

[0099] Following the process described above, sub-packaging and build tasks can be assigned to K processes. Among the remaining MK processes, the sub-packaging and build tasks assigned to each process may involve at least two terminal platforms. However, the allocation of sub-packaging and build tasks still adheres to the principle of ensuring that the overall runtime of the multiple processes is approximately the same.

[0100] In this embodiment, after step 820, the sub-packaging build tasks that are not assigned to any process are referred to as remaining sub-packaging build tasks, and the processes that are not assigned to any packaging build tasks are referred to as remaining processes. It can be understood that the number of remaining processes is MK. The total packaging build time corresponding to a remaining process is the sum of the packaging build times of all sub-packaging build tasks assigned to that remaining process in step 830. Since the time difference between the total packaging build time corresponding to a remaining process and the reference time does not exceed the second threshold, this ensures that after allocation, the expected runtime of the remaining process is relatively close to the expected runtime of other processes.

[0101] Correspondingly, before step 231, the method further includes: step 840, sorting at least one sub-build task executed by the same process to determine the task execution order of each process, wherein the sub-packaging build tasks corresponding to multiple running environments on the same terminal platform have consecutive sequence numbers in the task execution order of the corresponding process.

[0102] It is understandable that if at least one sub-build task executed by a process resides on the same terminal platform, the sub-build tasks executed by that process can be arbitrarily ordered. Regardless of the order, it can be guaranteed that the sub-packaging build tasks corresponding to multiple runtime environments on the same terminal platform will have consecutive sequence numbers in the task execution order of the corresponding process. For example, if the sub-packaging build tasks executed by process X1 include: sub-packaging build task 1, sub-packaging build task 2, and sub-packaging build task 3, and the runtime environments corresponding to these three sub-packaging build tasks reside on the same terminal platform, then the task execution order (from first to last) for process X1 can be: sub-packaging build task 1 → sub-packaging build task 2 → sub-packaging build task 3, or sub-packaging build task 2 → sub-packaging build task 3 → sub-packaging build task 1, or sub-packaging build task 3 → sub-packaging build task 1 → sub-packaging build task 2.

[0103] If a process is responsible for executing at least one sub-build task, which includes at least two sub-build tasks located on different terminal platforms, then when sorting, it is sufficient to ensure that the sub-packaging build tasks corresponding to multiple runtime environments located on the same terminal platform have consecutive sequence numbers in the task execution sorting of the corresponding process.

[0104] For example, if the sub-packaging build tasks executed by process X2 include: sub-packaging build task 6, sub-packaging build task 7, and sub-packaging build task 8, where the runtime environments corresponding to sub-packaging build task 7 and sub-packaging build task 8 are located on the same terminal platform, and the runtime environment corresponding to sub-packaging build task 6 is located on a different terminal platform than the runtime environment corresponding to sub-packaging build task 8, then the task execution order (from first to last) for process X2 can be: sub-packaging build task 6 → sub-packaging build task 7 → sub-packaging build task 8, or sub-packaging build task 6 → sub-packaging build task 8 → sub-packaging build task 7, or sub-packaging build task 7 → sub-packaging build task 8 → sub-packaging build task 6, etc.

[0105] Correspondingly, step 231 includes: step 2311, running M processes in parallel, so that each process, according to the task information of the sub-packaging and building task it is responsible for, packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for in order of task execution, and obtains the corresponding packaged file.

[0106] By assigning sub-packaging build tasks to each process according to the above process, it is possible to ensure that the sub-packaging build tasks corresponding to multiple runtime environments on the same terminal platform are assigned to the same process as much as possible. Moreover, it ensures that while a process is executing the assigned multiple sub-packaging build tasks, the sub-packaging build tasks corresponding to multiple runtime environments on the same terminal platform are executed consecutively.

[0107] Considering that during the execution of sub-build tasks, a process needs to load the resources required for the build process (such as dependencies and software packages) into memory, and that the shared resources between sub-build tasks on different terminal platforms are relatively few, while the shared resources between sub-build tasks on the same terminal platform are more numerous, the following approach can be used to allocate sub-build tasks corresponding to multiple terminal platforms to the same process as much as possible. Furthermore, by ensuring that the sub-build tasks corresponding to multiple terminal platforms are executed consecutively within a single process, it can be guaranteed that for a single process, the shared resources required by sub-build tasks on the same terminal platform only need to be loaded once, rather than multiple times. This further reduces the overall execution time of multiple sub-build tasks.

[0108] In some embodiments, such as Figure 9As shown, in addition to step 810, step 720 may also include the following steps 910-920:

[0109] Step 910: If K > M, assign the sub-packaging and building tasks located in the same group among the M groups with the longest total packaging and building time among the K groups to one of the M processes.

[0110] In this case, for each group, the packaging and building times of all sub-packaging and building tasks in each group can be added together to obtain the total packaging time for each group. Then, the K groups with the highest total packaging time can be determined from the K groups.

[0111] In this way, the initial sub-packaging build tasks assigned to each of the M processes are all running on the same terminal platform. Since the sub-packaging build tasks in one of the M groups with the longest total packaging build time are assigned to one of the M processes, the number of subsequent sub-packaging build tasks that can be assigned to that process is relatively small, provided that the overall runtime differences between the different processes are small.

[0112] Step 920: The packaging and building time of the sub-build tasks in the other groups (excluding M groups) of the K groups is allocated to each of the M processes, so that the difference in the total packaging and building time between any two processes does not exceed the first threshold.

[0113] By assigning sub-packaging build tasks to a process in the manner described above, it can be ensured that, when K > M, among the multiple sub-packaging build tasks assigned to a process, the number of sub-packaging build tasks whose corresponding runtime environments are located on the same terminal platform is relatively large, while the number of sub-packaging build tasks located on other terminal platforms is relatively small.

[0114] Correspondingly, before step 231, the method further includes: step 840, sorting at least one sub-build task executed by the same process to determine the task execution order of each process, wherein the sub-packaging build tasks corresponding to multiple running environments on the same terminal platform have consecutive sequence numbers in the task execution order of the corresponding process.

[0115] Correspondingly, step 231 includes: step 2311, running M processes in parallel, so that each process, according to the task information of the sub-packaging and building task it is responsible for, packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for in order of task execution, and obtains the corresponding packaged file.

[0116] Based on the above embodiments, when K≥M, allocating tasks in the above manner ensures that: among the multiple sub-packaging build tasks allocated to a process, the number of sub-packaging build tasks whose corresponding runtime environments are on the same terminal platform is relatively large, while the number of sub-packaging build tasks located on other terminal platforms is relatively small; moreover, ensuring that a subsequent process will continuously execute multiple sub-packaging build tasks whose corresponding runtime environments are on the same terminal platform also ensures that the resources shared by multiple sub-packaging build tasks whose corresponding runtime environments are on the same terminal platform are loaded only once, instead of being loaded multiple times, which can shorten the overall execution time of multiple sub-build tasks.

[0117] In some embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; before step 230, the method further includes: deleting the second source file address of the unchanged front-end source file from the task information of each sub-packaging and building task, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0118] In a runtime environment, the incremental front-end source files contain code that has changed compared to the previous version, while the unchanged front-end source files contain code that has remained unchanged from the previous version. It's understood that for a given runtime environment, there can be one or more incremental front-end source files, and similarly, there can be one or more unchanged front-end source files. For clarity, the file path of the incremental front-end source file is referred to as the first source file path, and the file path of the unchanged front-end source file is referred to as the second source file path.

[0119] In this embodiment, considering that after the target application is first released, subsequent updates usually involve updating only a portion of the target application's source code, it is possible to package and build only the changed source code, rather than packaging and building the entire source code.

[0120] For the front-end source files of the target application in a runtime environment, each file includes both incremental and unchanged front-end source files. Therefore, for each sub-packaging build task, the second source file address of the unchanged front-end source file corresponding to that sub-packaging build task is removed from its task information. This ensures that when retrieving code files according to the source file address in the task information, only the corresponding incremental front-end source file is retrieved, not the unchanged front-end source file. This guarantees that only the corresponding incremental front-end source file is packaged and built, resulting in the corresponding packaged file. It's important to understand that the packaged file obtained in this case for the target application in a runtime environment is the packaged result corresponding to the incremental front-end source files in that runtime environment, not the packaged result of all front-end source files.

[0121] In this embodiment, the address of the second source file that has not been modified in each sub-packaging and build task is deleted. This ensures that when the sub-packaging and build task is executed later, only the incremental front-end source file is packaged and built, and the unmodified front-end source file is not packaged and built. The unmodified front-end source file is equivalent to continuing to use the previous packaging and build result. In this way, the amount of source code to be packaged and built is reduced, which can also reduce the overall packaging and build time of the target application. In addition, the data volume of the packaged file is reduced, which can also reduce the communication resource consumption and distribution cost of distributing the packaged file.

[0122] In other embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; before step 230, the method further includes the following ①-②:

[0123] ①Based on the dependencies between different business functions in the target application, identify at least one dependent business function that has a dependency relationship with the target business function to which the incremental front-end source file belongs.

[0124] The business function description information of the target application can be obtained from the code development platform. This description information indicates the business functions involved in the target application and the dependencies between different business functions. If the implementation of business function A depends on the processing result of another business function B, it can be determined that business function A and business function B have a dependency relationship. Of course, the target application may also have two business functions that do not have a dependency relationship and are independent of each other.

[0125] The incremental front-end source files may include multiple files, and each file may belong to a different business function. In this application, the business function to which the incremental front-end source files belong is referred to as the target business function. That is, the source code in the incremental source files is the source code used to implement the target business function.

[0126] ② In the task information of each sub-packaging build task, delete the second source file address of the unmodified front-end source file other than the unmodified front-end source file representing at least one dependent business function, so that during the execution of a sub-packaging build task, the incremental front-end source file pointed to by the first source file address in the corresponding task information and the unmodified front-end source file pointed to by the second source file address representing at least one dependent business function are packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0127] In the task information of a sub-package build task, the second source file address of all unchanged front-end source files except those representing at least one dependent business function is deleted. This way, the task information of a sub-package build task retains the first source file address of the corresponding incremental front-end source file and the second source file address of the unchanged front-end source file representing at least one dependent business function that has a dependency relationship with the target business function. Subsequently, based on the task information of the sub-package build task, the incremental front-end source file and the unchanged front-end source file representing at least one dependent business function that has a dependency relationship with the target business function can be obtained. Unchanged front-end source files of other business functions that do not have a dependency relationship with the target business function will not be obtained, nor will they be packaged and built. This also reduces the amount of source code data in the package build and shortens the package build time.

[0128] Furthermore, in this embodiment, since the unchanged front-end source files of at least one dependent business function that depends on the target business function are also packaged and built, it avoids the situation where only the incremental front-end source files are packaged and built. This prevents incompatibility or conflicting processing logic between the packaged and built results of the incremental front-end source files and the previous packaged and built results of the unchanged front-end source files of at least one dependent business function that depends on the target business function, thus preventing the target application from running in the corresponding runtime environment. Therefore, the solution in this embodiment not only reduces the amount of source code data in the packaged and built process but also effectively ensures that the target application can run effectively in the corresponding runtime environment after packaging and building.

[0129] In some embodiments, before step 230, for each sub-packaging build task, the following processing can be performed respectively: based on the dependency relationship between different business functions in the target application, determine whether there is at least one dependent business function that has a dependency relationship with the target business function to which the incremental front-end source file belongs.

[0130] If it does not exist, delete the address of the second source file that has not been changed in the sub-packaging and build task, so that during the execution of the sub-packaging and build task, the incremental front-end source file pointed to by the first source file address in the corresponding task information will be packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0131] If it exists, delete the second source file address from the task information of the sub-packaging build task, except for the unmodified front-end source file that represents at least one dependent business function. This will allow the incremental front-end source file pointed to by the first source file address and the unmodified front-end source file that represents at least one dependent business function pointed to by the second source file address in the corresponding task information to be packaged and built, so as to obtain the packaged file of the target application in the corresponding runtime environment.

[0132] In this way, based on the dependencies between the target business function and other business functions to which the incremental front-end source file belongs, if it is determined that the target business function has no dependencies on other business functions, only the incremental front-end source file can be packaged and built; if it is determined that the target business function has at least one dependent business function, the incremental front-end source file and the unchanged front-end source file of at least one dependent business function that has a dependency on the target business function are combined to ensure that the target application can run normally in the corresponding runtime environment based on the obtained packaged file.

[0133] The following describes an apparatus embodiment of this application, which can be used to perform the methods described in the above embodiments of this application. For details not disclosed in the apparatus embodiments of this application, please refer to the method embodiments described in the above embodiments of this application.

[0134] Figure 10 This is a block diagram of a packaging and building apparatus for an application according to an embodiment of this application, such as... Figure 10As shown, the packaging and building device for this application includes: an acquisition module 1010, used to acquire runtime environment indication information of the target application; the runtime environment indication information indicates N runtime environments of the target application; N is an integer greater than 1; a task splitting module 1020, used to split the packaging and building task of the target application into N sub-packaging and building tasks according to the N runtime environments of the target application, and generate task information for the N sub-packaging and building tasks; wherein, the task information of a sub-packaging and building task includes the source file address of the front-end source file of the target application in one runtime environment; and a parallel execution module 1030, used to execute at least two of the N sub-packaging and building tasks in parallel according to the corresponding task information, until all N sub-packaging and building tasks are executed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application running in the runtime environment corresponding to the sub-packaging and building task.

[0135] In some embodiments, the task information further includes the packaging and building time of the sub-packaging and building tasks; the packaging and building device of the application further includes: a process creation module, used to create M processes; 2≤M≤N, where M is an integer; a process allocation module, used to allocate processes to N sub-packaging and building tasks in the M processes according to the packaging and building time of each sub-packaging and building task, and determine at least one sub-packaging and building task that each process in the M processes is responsible for executing; wherein, the time difference between the total packaging and building time of at least one sub-packaging and building task executed by any two processes does not exceed a first threshold; a parallel execution module, including: a parallel running unit, used to run the M processes in parallel, so that each process packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for according to the task information of the sub-packaging and building task it is responsible for, to obtain the corresponding packaged file.

[0136] In some embodiments, M < N, the process allocation module 1030 includes: a grouping unit, configured to group N sub-packaging build tasks into K groups according to the terminal platforms corresponding to each of the N running environments; wherein the running environments corresponding to the sub-packaging build tasks in the same group are located on the same terminal platform, and the running environments corresponding to the sub-packaging build tasks in different groups are located on different terminal platforms, 2 ≤ K < N; a first allocation unit, configured to allocate at least one sub-packaging build task in the same group whose cumulative packaging build time and reference time do not exceed a second threshold to the same process if K ≤ M; the second threshold does not exceed a first threshold; a second allocation unit, configured to allocate the remaining sub-packaging build tasks in the K groups to the remaining processes in the M processes that have not been allocated sub-packaging build tasks, based on the packaging build time of the remaining sub-packaging build tasks in the K groups; wherein the time difference between the total packaging build time of a remaining process and the reference time does not exceed the second threshold.

[0137] In some embodiments, the process allocation module further includes: a third allocation unit, configured to, if K > M, allocate the sub-packaging and building tasks located in the same group among the M groups with the longest total packaging and building time in the K groups to one of the M processes; and a fourth allocation unit, configured to allocate the packaging and building time of the sub-building tasks in the other groups among the K groups to each of the M processes, so that the time difference of the total packaging and building time corresponding to any two processes does not exceed a first threshold.

[0138] In some embodiments, the application's packaging and building apparatus further includes: a sorting module, configured to sort at least one sub-build task executed by the same process, and determine the task execution order corresponding to each process, wherein the sub-packaging and building tasks corresponding to multiple runtime environments located on the same terminal platform have consecutive sequence numbers in the task execution order of the corresponding processes; and a parallel running unit, configured to: run M processes in parallel, so that each process, according to the task information of the sub-packaging and building task it is responsible for, sequentially packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for, according to the corresponding task execution order, to obtain the corresponding packaged file.

[0139] In some embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; the application packaging and building apparatus further includes: a first deletion module, used to delete the second source file address of the unchanged front-end source file from the task information of each sub-packaging and building task, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0140] In other embodiments, the front-end source file includes an incremental front-end source file and an unchanged front-end source file; the source file address of the front-end source file includes a first source file address of the incremental front-end source file and a second source file address of the unchanged front-end source file; correspondingly, the application packaging and building device further includes: a dependency determination module, used to determine at least one dependent business function that has a dependency relationship with the target business function to which the incremental front-end source file belongs, based on the dependency relationship between different business functions in the target application; and a second deletion module, used to delete the second source file addresses of other unchanged front-end source files (excluding those representing at least one dependent business function) from the task information of each sub-packaging and building task, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address and the unchanged front-end source file pointed to by the second source file address in the corresponding task information, representing at least one dependent business function, are packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

[0141] In some embodiments, the parallel execution module is used to: execute each sub-packaging and building task according to the following process using the packaging and building tool: obtain the corresponding front-end source file according to the source file address in the task information of the sub-packaging and building task; parse the front-end source file to obtain the parsing result; compile the front-end source file using the loader in the packaging and building tool to obtain the compilation result; and generate the packaged file of the target application in the runtime environment corresponding to the sub-packaging and building task based on the compilation result and the parsing result.

[0142] In some embodiments, the loader includes a first loader for compiling logic files in the front-end source files; the application packaging and building apparatus further includes: an instruction acquisition module for acquiring a loader replacement instruction; and a replacement module for replacing the default loader in the packaging and building tool for compiling logic files with the first loader in response to the loader replacement instruction; the first loader has a faster compilation speed than the default loader.

[0143] In some embodiments, the method is executed by an electronic device, and the process creation module is used to: obtain the number of cores of the electronic device; and use the number of cores as M to create M processes.

[0144] Figure 11 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 11 The computer system 1100 of the illustrated electronic device is merely an example and should not be construed as limiting the functionality and scope of use of the embodiments of this application. This electronic device can be used to execute the packaging and building method for the applications provided in this application.

[0145] like Figure 11 As shown, the computer system 1100 includes a Central Processing Unit (CPU) 1101, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 1102 or programs loaded from storage portion 1108 into Random Access Memory (RAM) 1103. The RAM 1103 also stores various programs and data required for system operation. The CPU 1101, ROM 1102, and RAM 1103 are interconnected via a bus 1104. An Input / Output (I / O) interface 1105 is also connected to the bus 1104.

[0146] The following components are connected to I / O interface 1105: an input section 1106 including a keyboard, mouse, etc.; an output section 1107 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1108 including a hard disk, etc.; and a communication section 1109 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1109 performs communication processing via a network such as the Internet. A drive 1110 is also connected to I / O interface 1105 as needed. Removable media 1111, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1110 as needed so that computer programs read from them can be installed into storage section 1108 as needed.

[0147] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1109, and / or installed from removable medium 1111. When the computer program is executed by central processing unit (CPU) 1101, it performs various functions defined in the system of this application.

[0148] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such transmitted data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0149] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0150] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.

[0151] In another aspect, this application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into the electronic device. The aforementioned computer-readable storage medium carries computer-readable instructions that, when executed by a processor, implement the methods in any of the above embodiments.

[0152] In the embodiments of this application, the terms "module" or "unit" refer to a computer program or part of a computer program that has a predetermined function and works with other related parts to achieve a predetermined goal. It can be implemented wholly or partially using software, hardware (e.g., processing circuitry or memory), or a combination thereof. Similarly, a processor (or multiple processors or memory) can be used to implement one or more modules or units. Furthermore, each module or unit can be part of an overall module or unit that functions as a whole.

[0153] According to one aspect of the embodiments of this application, a computer program product is provided, the computer program product including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the methods of any of the above embodiments.

[0154] It should be noted that although several modules or units for the device used to perform actions have been mentioned in the detailed description above, this division is not mandatory. In fact, according to the embodiments of this application, the features and functions of two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.

[0155] Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the method according to the embodiments of this application.

[0156] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the embodiments disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein.

[0157] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.

Claims

1. A method for packaging and building an application, characterized in that, include: Obtain runtime environment indication information for the target application; The runtime environment indication information is used to indicate the N runtime environments of the target application; N is an integer greater than 1; Based on the N runtime environments of the target application, the packaging and building task of the target application is divided into N sub-packaging and building tasks, and task information of the N sub-packaging and building tasks is generated; wherein, the task information of one of the sub-packaging and building tasks includes the source file address of the front-end source file of the target application in one runtime environment; Based on the corresponding task information, at least two of the N sub-packaging and building tasks are executed in parallel until all N sub-packaging and building tasks are completed. During the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain the packaged file in which the target application runs in the runtime environment corresponding to the sub-packaging and building task.

2. The method according to claim 1, characterized in that, The task information also includes the packaging and building time of the sub-packaging and building task; The method further includes, based on the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks have been executed. Create M processes; 2 ≤ M ≤ N, where M is an integer; Based on the packaging and building time of each of the sub-packaging and building tasks, process allocation is performed for each of the N sub-packaging and building tasks in the M processes, and at least one sub-packaging and building task is determined to be executed by each of the M processes; wherein, the difference in the total packaging and building time of at least one sub-packaging and building task executed by any two processes does not exceed a first threshold. The step of executing at least two of the N sub-packaging and building tasks in parallel according to the corresponding task information, until all N sub-packaging and building tasks have been executed, includes: The M processes are run in parallel, so that each process packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for according to the task information of the sub-packaging and building task it is responsible for, so as to obtain the corresponding packaged file, until all N sub-packaging and building tasks have been executed.

3. The method according to claim 2, characterized in that, When M < N, the process of allocating processes among the M processes for each of the N sub-packaging and building tasks based on the packaging and building time of each of the M processes, and determining at least one sub-packaging and building task to be executed by each of the M processes, includes: Based on the terminal platform corresponding to each of the N operating environments, the N sub-packaging and building tasks are grouped into K groups; wherein, the operating environments corresponding to the sub-packaging and building tasks in the same group are located on the same terminal platform, and the operating environments corresponding to the sub-packaging and building tasks in different groups are located on different terminal platforms, and 2≤K<N. If K≤M, at least one sub-packaging and building task located in the same group whose cumulative packaging and building time difference from the reference time does not exceed the second threshold will be assigned to the same process; the second threshold does not exceed the first threshold; Based on the packaging and building time of the remaining sub-packaging and building tasks of the unassigned processes in the K groups, the remaining sub-packaging and building tasks of the unassigned processes in the M processes are allocated among the remaining processes of the unassigned sub-packaging and building tasks; wherein, the time difference between the total packaging and building time corresponding to a remaining process and the reference time does not exceed the second threshold.

4. The method according to claim 3, characterized in that, After grouping the N sub-packaging and building tasks into K groups based on the terminal platforms corresponding to each of the N operating environments, the method further includes: If K > M, the sub-packaging and building tasks located in the same group among the M groups with the longest total packaging and building time among the K groups will be assigned to one of the M processes. The packaging and building time of the sub-build tasks in the other groups besides the M groups in the K groups is allocated to each of the M processes, so that the difference in the total packaging and building time between any two processes does not exceed the first threshold.

5. The method according to claim 3 or 4, characterized in that, The method further includes, based on the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks have been executed. The at least one sub-build task executed by the same process is sorted to determine the task execution order of each process, wherein the sub-packaging build tasks corresponding to multiple runtime environments on the same terminal platform have consecutive sequence numbers in the task execution order of the corresponding process. The M processes are run in parallel so that each process packages and builds the front-end source files corresponding to its assigned sub-packaging and building task according to the task information of that task, resulting in a corresponding packaged file, including: The M processes are run in parallel so that each process, according to the task information of the sub-packaging and building task it is responsible for, packages and builds the front-end source files corresponding to the sub-packaging and building task it is responsible for in order of task execution, and obtains the corresponding packaged file.

6. The method according to any one of claims 1 to 5, characterized in that, The front-end source files include incremental front-end source files and unchanged front-end source files; the source file addresses of the front-end source files include the first source file address of the incremental front-end source files and the second source file address of the unchanged front-end source files; The method further includes, based on the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks have been executed. The second source file address of the unchanged front-end source file in the task information of each sub-packaging and building task is deleted, so that during the execution of a sub-packaging and building task, the incremental front-end source file pointed to by the first source file address in the corresponding task information is packaged and built to obtain the packaged file of the target application in the corresponding running environment.

7. The method according to any one of claims 1 to 5, characterized in that, The front-end source files include incremental front-end source files and unchanged front-end source files; the source file addresses of the front-end source files include the first source file address of the incremental front-end source files and the second source file address of the unchanged front-end source files. The method further includes, based on the corresponding task information, executing at least two of the N sub-packaging and building tasks in parallel until all N sub-packaging and building tasks have been executed. Based on the dependencies between different business functions in the target application, determine at least one dependent business function that has a dependency relationship with the target business function to which the incremental front-end source file belongs; In the task information of each sub-packaging build task, the second source file address of the unmodified front-end source file other than the unmodified front-end source file representing the at least one dependent business function is deleted. This is so that during the execution of a sub-packaging build task, the incremental front-end source file pointed to by the first source file address and the unmodified front-end source file pointed to by the second source file address in the corresponding task information are packaged and built to obtain the packaged file of the target application in the corresponding runtime environment.

8. The method according to any one of claims 1 to 5, characterized in that, The sub-packaging and build tasks are executed using the packaging and build tool according to the following process: Obtain the corresponding front-end source file according to the source file address in the task information of the sub-packaging and building task; The front-end source file is parsed to obtain the parsing result; The front-end source files are compiled using the loader in the packaging and build tool to obtain the compilation result; Based on the compilation results and the parsing results, a package file for the target application in the runtime environment corresponding to the sub-packaging build task is generated.

9. The method according to claim 8, characterized in that, The loader includes a first loader for compiling the logic files in the front-end source files; Before compiling the front-end source files using the loader in the packaging and building tool to obtain the compilation result, the method further includes: Retrieve loader replacement instructions; In response to the loader replacement instruction, the default loader used for compiling logic files in the packaging build tool is replaced with the first loader; the compilation speed of the first loader is faster than that of the default loader.

10. The method according to claim 2, characterized in that, The method is executed by an electronic device, and the creation of M processes includes: Obtain the number of cores in the electronic device; Let the number of cores be M, and create M processes.

11. An application packaging and building apparatus, characterized in that, include: The acquisition module is used to obtain runtime environment indication information of the target application; The runtime environment indication information is used to indicate the N runtime environments of the target application; N is an integer greater than 1; The task splitting module is used to split the packaging and building task of the target application into N sub-packaging and building tasks according to the N runtime environments of the target application, and generate task information for the N sub-packaging and building tasks; wherein, the task information of one of the sub-packaging and building tasks includes the source file address of the front-end source file of the target application in one runtime environment; The parallel execution module is used to execute at least two of the N sub-packaging and building tasks in parallel according to the corresponding task information, until all N sub-packaging and building tasks are completed; wherein, during the execution of a sub-packaging and building task, the front-end source file pointed to by the source file address in the corresponding task information is packaged and built to obtain the packaged file in which the target application runs in the runtime environment corresponding to the sub-packaging and building task.

12. An electronic device, characterized in that, include: processor; A memory storing computer-readable instructions that, when executed by the processor, implement the method as described in any one of claims 1-10.

13. A computer-readable storage medium storing computer-readable instructions thereon, characterized in that, When the computer-readable instructions are executed by a processor, the method as described in any one of claims 1-10 is implemented.

14. A computer program product comprising computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the method of any one of claims 1-10.