A project packaging method, device and computer equipment
By packaging UI components on demand and using the UI component dependency mapping table to determine the components required for the target project, the problems of large size and slow loading caused by full packaging are solved, and smaller packaged products and faster loading speeds are achieved.
Patent Information
- Application Number
- CN202110708438.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-24
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2041-06-24
AI Technical Summary
In the existing technology, the full introduction of UI components leads to problems such as large product size, large storage space occupied, and slow loading speed when packaging front-end projects.
By obtaining the code to be packaged of the target project, package it into a business file package and a framework file package, obtain the UI component name, determine the required UI components according to the preset UI component dependency mapping table, and package and reset on demand The UI component import file in the business file package.
It is possible to package only the components used in the project, reducing the size of the packaged product, saving storage space, and improving the page loading speed.
Smart Images

Figure CN113312109B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a project packaging method, device and computer equipment. Background Art
[0002] At present, most of the front-end project projects based on the module packager (web pack) need to use the UI components in the UI component library. When the front-end project projects in the related technology are packaged, the method of introducing UI components is to introduce all the components in the UI component library. However, a front-end project project only needs some components in the UI component library, not all UI components in the UI component library. In this way, when the project is packaged, unused UI components will also be packaged together, which makes the packaged product too large and occupies a large storage space. Summary of the invention
[0003] Therefore, the technical problem to be solved by the present invention is to overcome the defects in the prior art that the full amount of components is introduced, resulting in large volume and large storage space occupied by the packaged product when the project is packaged, thereby providing a project packaging method, device and computer equipment.
[0004] According to a first aspect, the present invention discloses a project packaging method, comprising the following steps: obtaining the code to be packaged of a target project; packaging the code to be packaged into a business file package and a framework file package; obtaining the UI component name in the business file package; determining the UI component required for the target project according to a preset UI component dependency mapping table and the UI component name in the business file package; resetting the UI component import file in the business file package according to the UI component required for the target project and packaging it.
[0005] Optionally, obtaining the UI component name in the business file package includes: obtaining a preset plug-in; and removing the UI component name in the comment code in the business file package according to the preset plug-in.
[0006] Optionally, the UI component dependency mapping table is established through the following steps: obtaining source code of a UI component library; determining UI component dependencies according to a header file of the source code of the UI component library; and constructing the UI component dependency mapping table according to the UI component dependencies.
[0007] Optionally, before obtaining the code to be packaged of the target project, the method further includes: obtaining a UI component library; and determining the code to be packaged of the target project according to UI components in the UI component library in response to a component call request.
[0008] Optionally, the method for obtaining the UI component name includes: js regular expression matching and ast abstract syntax tree analysis.
[0009] According to the second aspect, the present invention also discloses a project packaging device, including: a first acquisition module, used to obtain the code to be packaged of the target project; a first packaging module, used to package the code to be packaged into a business file package and a framework file package; a second acquisition module, used to obtain the UI component name in the business file package; a component to be packaged determination module, used to determine the UI component required for the target project according to a preset UI component dependency mapping table and the UI component name in the business file package; a second packaging module, used to reset the UI component import file in the business file package according to the UI component required by the target project and package it.
[0010] Optionally, the second acquisition module includes: a second acquisition submodule, used to acquire a preset plug-in; and a removal module, used to remove the UI component name in the comment code in the business file package according to the preset plug-in.
[0011] Optionally, the device also includes: a third acquisition module, used to acquire the source code of the UI component library; a component dependency determination module, used to determine the UI component dependency based on the header file of the source code of the UI component library; and a construction module, used to construct the UI component dependency mapping table based on the UI component dependency.
[0012] According to the third aspect, the present invention also discloses a computer device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the project packaging method as described in the first aspect or any optional embodiment of the first aspect.
[0013] According to a fourth aspect, the present invention further discloses a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the project packaging method as described in the first aspect or any optional implementation manner of the first aspect.
[0014] The technical solution of the present invention has the following advantages:
[0015] The project packaging method and device provided by the present invention obtains the code to be packaged of the target project, packages the code to be packaged into a business file package and a framework file package; obtains the UI component name in the business file package, determines the UI component required for the target project according to the preset UI component dependency mapping table and the UI component name in the business file package, resets the UI component introduction file in the business file package according to the UI component required for the target project, and packages. When the present invention performs project packaging, the components to be introduced on demand are determined according to the preset component dependency mapping table and the component name in the business file package, and then only the components used in the project are packaged, and the full packaging in the prior art is changed to on-demand packaging, the volume of the packaged product becomes smaller, the storage space is saved, the page loading volume is reduced, and the loading speed is accelerated. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 A flowchart of a specific example of a project packaging method in an embodiment of the present invention;
[0018] Figure 2 It is a principle block diagram of a specific example of a project packaging device in an embodiment of the present invention;
[0019] Figure 3 FIG. 4 is a specific example diagram of a computer device in an embodiment of the present invention. DETAILED DESCRIPTION
[0020] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0021] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0022] In the description of the present invention, it should be noted that, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, it can also be the internal connection of two components, it can be a wireless connection, or it can be a wired connection. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0023] In addition, the technical features involved in the different embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0024] The embodiment of the present invention discloses a project packaging method, such as Figure 1 As shown, the following steps are included:
[0025] S11: Obtain the code to be packaged of the target project.
[0026] Exemplarily, in the embodiment of the present invention, the target project refers to a front-end project, and its code to be packaged can be stored in a memory, directly obtained from the memory when used, or directly opened and run in the running environment. The embodiment of the present invention does not specifically limit the code to be packaged of the target project, and those skilled in the art can determine it according to actual conditions.
[0027] S12: Package the code to be packaged into a business file package and a framework file package.
[0028] Exemplarily, the framework file package is a collection of framework files, which refer to files other than business files, and the framework files may include referenced plug-ins, code files at the project framework level, etc. The embodiment of the present invention does not specifically limit the framework file, and those skilled in the art may determine it according to actual conditions. The business file package is a collection of business files, which refer to files corresponding to the routes in the routing configuration and the files they depend on.
[0029] In the embodiment of the present invention, the webpack plug-in webpack.optimize.CommonsChunkPlugin is used to classify and package the code to be packaged into business file packages and framework file packages. For example, all corresponding files are packaged into vuedor.js file (i.e. framework file package) through path screening, and all files under the file module node_modules path are packaged into src / home / index.vue business file package.
[0030] S13: Obtain the UI component name in the business file package.
[0031] Exemplarily, the UI component name refers to the UI component directly referenced in the business file, which can be an English name (for example, Loading), a Chinese name (for example, Payment), or a custom name. The embodiment of the present invention does not specifically limit the UI component name, and those skilled in the art can determine it according to the actual naming situation. The UI component name can be obtained using a custom converter written by oneself (such as ox-components-transform-loader). The specific acquisition method may include: js regular expression matching, ast abstract syntax tree analysis, etc. The embodiment of the present invention does not specifically limit the method for obtaining the UI component name, and those skilled in the art can determine it according to the actual situation.
[0032] S14: Determine the UI components required for the target project according to the preset UI component dependency mapping table and the UI component names in the business file package.
[0033] Exemplarily, the preset UI component dependency mapping table can be constructed in advance according to the UI component library, and the specific construction method is as follows:
[0034] First, the source code of the UI component library is obtained. The source code of the UI component library can be directly obtained by calling a function. Secondly, the header file of the source code of the UI component library records the reference relationship of each UI component, and the UI component dependency relationship is determined according to the header file of the source code of the UI component library; and a UI component dependency mapping table is constructed according to the UI component dependency relationship.
[0035] Determining the UI components required for the target project according to the preset UI component dependency mapping table and the component names in the business file package can specifically be determining the UI components that each UI component depends on according to the UI component names obtained above and the preset UI component dependency mapping table. In an embodiment of the present invention, the UI components that each UI component depends on are determined by the plug-in ox-components-transform-loader, and then the UI components corresponding to the UI component names obtained above and the UI components that a UI component depends on are determined together as the UI components required for the target project.
[0036] When the dependent UI components of the UI component corresponding to the UI component name obtained above are determined, all UI component names are output into an intermediate file through the node's operation file method, for example, ['el-slider', 'el-switch', 'el-button'], where el-slider, el-switch and el-button are all UI component names.
[0037] S15: reset the UI component import files in the business file package according to the UI components required by the target project and package them.
[0038] Exemplarily, according to the UI components required by the target project, the full import UI component package in the business file package is reset to the on-demand import package, that is, the main function is changed from full import to on-demand import. Depending on the component type, the on-demand import type of the component may include: ordinary component import, instruction import, css import, global method import, etc. The embodiment of the present invention does not specifically limit the type of component import, and those skilled in the art can determine it according to actual conditions.
[0039] The project packaging method provided by the present invention obtains the code to be packaged of the target project, packages the code to be packaged into a business file package and a framework file package; obtains the UI component name in the business file package, determines the UI component required for the target project according to the preset UI component dependency mapping table and the UI component name in the business file package, resets the UI component introduction file in the business file package according to the UI component required for the target project, and packages. When the present invention performs project packaging, the components to be introduced on demand are determined according to the preset component dependency mapping table and the component name in the business file package, and then only the components used in the project are packaged, and the full packaging in the prior art is changed to on-demand packaging, the volume of the packaging product becomes smaller, the storage space is saved, the page loading volume is reduced, and the loading speed is accelerated.
[0040] As an optional implementation of the embodiment of the present invention, when the comment in the business file contains the UI component name and the comment is not removed during packaging, when the business file is subsequently converted using ox-components-transform-loader, the UI component name in the comment will be extracted, resulting in inaccurate statistics of the used UI components. Therefore, it is necessary to remove the UI component name in the comment before counting the UI component name. The above step S13 includes:
[0041] First, get the preset plugin.
[0042] Exemplarily, the preset plug-in may be uglifyjs-webpack-plugin, which may be directly called from webpack. The embodiment of the present invention does not specifically limit the preset plug-in, and those skilled in the art may determine it according to actual conditions.
[0043] Secondly, according to the preset plug-in, remove the UI component name in the comment code in the business file package.
[0044] The embodiment of the present invention ensures the statistical correctness of the UI component names used in the target project by removing the UI component names contained in the comments of the business file, and further reduces useless UI components during packaging, thereby further reducing the size of the packaged product.
[0045] As an optional implementation of the embodiment of the present invention, in order to ensure the development experience of developers, before the above step S11, the project packaging method further includes:
[0046] First, obtain the UI component library. The UI component library can be directly called by calling the function. In the embodiment of the present invention, the UI components are fully introduced when the developer develops. Second, in response to the component call request, the code to be packaged of the target project is determined according to the UI components in the UI component library.
[0047] For example, when a researcher is developing a project, if he needs to use a UI component in a UI component library, he can directly call the component and determine the code to be packaged for the target project according to the UI component corresponding to the component call request.
[0048] The embodiment of the present invention introduces components in full during development and on demand during packaging, thereby taking into account the development experience of developers, allowing developers to focus on business development without paying too much attention to the packaging and compilation details introduced by the UI component library, while ensuring the weight reduction effect of the packaged product.
[0049] The embodiment of the present invention also discloses a project packaging device, such as Figure 2 As shown, including:
[0050] The first acquisition module 21 is used to acquire the to-be-packaged code of the target project; the specific implementation method is described in the relevant description of step S11 in the above embodiment, which will not be repeated here.
[0051] The first packaging module 22 is used to package the code to be packaged into a business file package and a framework file package; the specific implementation method is shown in the relevant description of step S12 in the above embodiment, which will not be repeated here.
[0052] The second acquisition module 23 is used to acquire the UI component name in the business file package; the specific implementation method is shown in the relevant description of step S13 in the above embodiment, which will not be repeated here.
[0053] The to-be-packaged component determination module 24 is used to determine the UI components required for the target project according to the preset UI component dependency mapping table and the UI component names in the business file package; the specific implementation method is described in the relevant description of step S14 in the above embodiment, which will not be repeated here.
[0054] The second packaging module 25 is used to re-pack the UI component import files in the business file package according to the UI components required by the target project. The specific implementation method is described in the relevant description of step S15 in the above embodiment, which will not be repeated here.
[0055] The project packaging device provided by the present invention obtains the code to be packaged of the target project, packages the code to be packaged into a business file package and a framework file package; obtains the UI component name in the business file package, determines the UI component required for the target project according to the preset UI component dependency mapping table and the UI component name in the business file package, resets the UI component introduction file in the business file package according to the UI component required for the target project, and packages. When the present invention packages the project, it determines the components to be introduced on demand according to the preset component dependency mapping table and the component name in the business file package, and then only packages the components used in the project, changes the full packaging in the prior art into on-demand packaging, reduces the size of the packaging product, saves storage space, reduces the page loading volume, and speeds up the loading speed.
[0056] As an optional implementation of the embodiment of the present invention, the second acquisition module 23 includes:
[0057] The second acquisition submodule is used to acquire a preset plug-in; the specific implementation method can be found in the relevant description of the corresponding steps in the above embodiment, which will not be repeated here.
[0058] The removal module is used to remove the UI component name in the comment code in the business file package according to the preset plug-in. The specific implementation method is shown in the relevant description of the corresponding steps in the above embodiment, which will not be repeated here.
[0059] As an optional implementation of the embodiment of the present invention, the project packaging device also includes:
[0060] The third acquisition module is used to obtain the source code of the UI component library; the specific implementation method can be found in the relevant description of the corresponding steps in the above embodiment, which will not be repeated here.
[0061] The component dependency determination module is used to determine the UI component dependency according to the header file of the source code of the UI component library; the specific implementation method can be found in the relevant description of the corresponding steps in the above embodiment, which will not be repeated here.
[0062] The construction module is used to construct a UI component dependency mapping table according to the UI component dependency relationship. The specific implementation method is described in the relevant description of the corresponding steps in the above embodiment, which will not be repeated here.
[0063] As an optional implementation of the embodiment of the present invention, the project packaging device also includes:
[0064] First, obtain the UI component library. The specific implementation method is described in the corresponding steps in the above embodiment, which will not be repeated here.
[0065] Secondly, in response to the component call request, the code to be packaged of the target project is determined according to the components in the UI component library.
[0066] As an optional implementation of the present invention, the method for obtaining the UI component name includes: js regular expression matching and ast abstract syntax tree analysis. The specific implementation method is described in the corresponding steps in the above embodiment, which will not be repeated here.
[0067] The embodiment of the present invention also provides a computer device, such as Figure 3 As shown, the computer device may include a processor 31 and a memory 32, wherein the processor 31 and the memory 32 may be connected via a bus or other means. Figure 3 The example of connecting through bus is taken in the following.
[0068] The processor 31 may be a central processing unit (CPU). The processor 31 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or a combination of the above chips.
[0069] The memory 32 is a non-transitory computer-readable storage medium that can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the project packaging method in the embodiment of the present invention (for example, Figure 2 The processor 31 executes various functional applications and data processing of the processor by running the non-transient software programs, instructions and modules stored in the memory 32, that is, the project packaging method in the above method embodiment is implemented.
[0070] The memory 32 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and applications required for at least one function; the data storage area may store data created by the processor 31, etc. In addition, the memory 32 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage devices. In some embodiments, the memory 32 may optionally include a memory remotely arranged relative to the processor 31, and these remote memories may be connected to the processor 31 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0071] The one or more modules are stored in the memory 32 and when executed by the processor 31, perform the following steps: Figure 1 The project packaging method in the illustrated embodiment.
[0072] For details of the above computer equipment, please refer to Figure 1 The corresponding related descriptions and effects in the illustrated embodiments can be understood and will not be repeated here.
[0073] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc.; the storage medium can also include a combination of the above-mentioned types of memory.
[0074] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A project packaging method, characterized in that: The steps include: Get the code to be packaged of the target project; Packaging the code to be packaged into a business file package and a framework file package; Obtain the UI component name in the business file package; Determine the UI components required for the target project according to a preset UI component dependency mapping table and the UI component names in the business file package; Reset the UI component import files in the business file package according to the UI components required by the target project and package them; The determining the UI components required for the target project according to the preset UI component dependency mapping table and the UI component names in the business file package includes: determining the UI components that each UI component depends on according to the UI component names in the business file package and the preset UI component dependency mapping table, and determining the UI components corresponding to the UI component names in the business file package and the UI components that each UI component depends on as the UI components required for the target project; The obtaining of the UI component name in the business file package includes: Get the preset plugin; The UI component name in the comment code in the business file package is removed according to the preset plug-in.
2. The method according to claim 1, characterized in that The UI component dependency mapping table is established through the following steps: Get the source code of the UI component library; Determine the UI component dependency relationship according to the header file of the source code of the UI component library; The UI component dependency mapping table is constructed according to the UI component dependency relationship.
3. The method according to claim 1, characterized in that Before obtaining the code to be packaged of the target project, the method further includes: Get the UI component library; In response to the component call request, the code to be packaged of the target project is determined according to the UI components in the UI component library.
4. The method according to claim 1, characterized in that: The method for obtaining the UI component name includes: js regular expression matching and ast abstract syntax tree analysis.
5. A project packaging device, characterized in that: include: The first acquisition module is used to obtain the code to be packaged of the target project; A first packaging module, used for packaging the code to be packaged into a business file package and a framework file package; The second acquisition module is used to acquire the UI component name in the business file package; A component determination module to be packaged, used to determine the UI components required for the target project according to a preset UI component dependency mapping table and the UI component names in the business file package; A second packaging module is used to reset the UI component import files in the business file package according to the UI components required by the target project and package them; The to-be-packaged component determination module is specifically used to determine the UI components that each UI component depends on according to the UI component names in the business file package and a preset UI component dependency mapping table, and determine the UI components corresponding to the UI component names in the business file package and the UI components that each UI component depends on as the UI components required by the target project; The second acquisition module includes: The second acquisition submodule is used to acquire the preset plug-in; A removal module is used to remove the UI component name in the comment code in the business file package according to the preset plug-in.
6. The device according to claim 5, characterized in that The device also includes: The third acquisition module is used to obtain the source code of the UI component library; A component dependency determination module, used to determine the UI component dependency according to the header file of the source code of the UI component library; A construction module is used to construct the UI component dependency mapping table according to the UI component dependency relationship.
7. A computer device, characterized in that: include: at least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor performs the steps of the project packaging method as described in any one of claims 1-4.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the project packaging method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Method and system for assembling modular products
CN105512955A
Webpack-based resource package compiling method and system, server and storage medium
CN111459497A
Packaging method and device, electronic equipment and storage medium
CN111736888A
Page generation method and device, computer equipment and storage medium
CN112882782A
Methods and apparatus for packaging a program for remote execution
US6493870B1
