Disclosure of Invention
The invention aims to provide a project architecture management method based on a Vue framework.
In order to achieve the above purpose, the present invention adopts the following technical scheme:
a method of project architecture management based on a Vue framework, comprising:
obtaining a scaffold Vite based on a Vue frame, and configuring a basic path as a path where a current catalog is located;
acquiring an execution command, acquiring plug-in components and storing the plug-in components in corresponding catalogues according to classification, wherein the acquired plug-in components comprise general components, js general function components, general pictures and style processing components, classifying the corresponding plug-in components according to development requirements, putting the corresponding plug-in components in the corresponding catalogues, traversing all the plug-in components according to the execution command, initializing the corresponding plug-in components after finishing the operation, and selecting whether to clean old files according to the requirements of the execution command;
generating a corresponding entry file according to the Vue frame;
and starting the terminal and entering a catalog of the project, executing a development task or a packaging task according to the execution command, reporting errors when the entry file is not found, ending the execution task, and calling a corresponding plug-in component to execute the corresponding task when the entry file is found.
Further, the acquiring and configuring the basic path as the path where the current directory is located specifically includes:
defining a config catalog according to the vite.config.ts of the scaffold Vite, and configuring a basic route as a route where the current catalog is located;
and configuring a path as an output path of a generated result after executing the command, and configuring a path as a storage path for generating the static resource.
Further, the plug-in components are provided with configuration files after being acquired, wherein the configuration files comprise a starting command, definable IP and port numbers, and each plug-in component is provided with a corresponding dependency library and plug-in code.
Further, after the entry file is found, processing the index html of the entry file, identifying whether CDN introduction dependence is needed, if so, calling a corresponding plug-in component and introducing the needed CDN data into the head label, and calling the plug-in component to compress the picture after the CDN data is introduced, and if not, calling the plug-in component to compress the picture;
judging whether secondary compression is needed or not according to an execution command, if yes, compressing all picture data, then calling a plug-in component to process js files, otherwise, directly calling the plug-in component to process js files, then processing css files, after configuring a path of a resource referenced in the files, storing the picture data, js file data and css file data in a designated directory, and finally generating a read.md file of the project.
After the technical scheme is adopted, compared with the background technology, the invention has the following advantages:
the invention puts the public components and the resource data into the appointed catalogue as the public resources on the basis of the scaffold vite of the Vue framework, and a user can introduce the public components and the resource data in any position in the same way, so that the manual copying is avoided, the later maintenance cost is improved, all the configuration and dependent packages in all projects are put into the appointed catalogue for unified management, the scaffold and the plug-in components are not required to be installed again after the projects are newly built, one execution command can be started, and the time and the space are reduced.
Detailed Description
The present invention will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
It should be noted that, in the present invention, terms "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. are all based on the orientation or positional relationship shown in the drawings, and are merely for convenience of describing the present invention and simplifying the description, and do not indicate or imply that the apparatus or element of the present invention must have a specific orientation, and thus should not be construed as limiting the present invention.
Referring to fig. 1, the invention discloses a project architecture management method based on a Vue framework, which comprises the following steps:
and acquiring a scaffold Vite based on the Vue framework, and configuring a basic path as a path where the current directory is located.
The base path (baseURL) refers to a base path when an application is built in the Vue framework, and a resource reference path of a subsequent application is to be based on the base path; specifically, for the Vue item, configuration is generally performed in a vue.config.js file; version after Vue CLI 3.3 discards the baseURL and changes to publicPath configuration item. The current directory refers to a current working directory in which a Vue building command is located when running in a command line; in this embodiment, the base path is configured as the path where the current directory is located, that is, the content of the publicPath configuration item in the vue.
The acquisition mode is an API for inquiring the official scaffold Vite document, and custom configuration is carried out on the defined scaffold Vite.
And acquiring an execution command, acquiring plug-in components and storing the plug-in components in a corresponding catalog according to classification, wherein the plug-in components are plug-in components required to be used for project development. The obtained plug-in component comprises a general component, a js general function component and a general picture and style processing component, and is used for preparing subsequent multi-project and unified maintenance. And classifying the corresponding plug-in components according to development requirements, putting the plug-in components into corresponding catalogues, traversing all the plug-in components according to the execution commands, initializing the corresponding plug-in components after finishing the operation, and selecting whether to clean old files according to the requirements of the execution commands.
And generating a corresponding entry file according to the Vue framework.
And starting the terminal and entering a catalog of the project, executing a development task or a packaging task according to the execution command, reporting errors when the entry file is not found, ending the execution task, and calling a corresponding plug-in component to execute the corresponding task when the entry file is found.
In this embodiment, a typical directory structure tree for the Vue item is as follows:
vue_basic
output directory after construction of item
├── node_modules
-dependency of type i/v
├── public
An index html// project main entry file
-other public resources,// and others
├── src
Level-levels// static resources
│└── logo.png
-components// common components
│└── HelloWorld.vue
I-plug ins// plug-in resources
│└── axios.js
' A router// routing configuration
…
The catalog of the item is a configured basic path;
specifically, in the configuration of the embodiment, the base path is configured as the path where the current directory is located, so that the base path, the current directory and the directory where the item is located point to the same path "vue _basic"; the plug-in stored directory refers to the "vue _basic/src/plug/" directory, and the component stored directory refers to the "vue _basic/src/components" directory.
The obtaining and configuring the basic path as the path of the current catalog specifically comprises:
and defining a config catalog according to the vite.config.ts of the scaffold Vite, and configuring a basic route as a route where the current catalog is located.
And configuring a path as an output path of a generated result after executing the command, and configuring a path as a storage path for generating the static resource.
The present embodiment also provides configuration content for the plug-in component, such as: automatic introduction of CDN resources, automatic picture compression, automatic creation of a snowplow map, automatic addition of css browser compatible prefixes, automatic confusion of compressed codes, automatic creation of readme description files and the like.
The plug-in component of this embodiment further includes a obfuscator for obfuscating the compressed code and provided with a corresponding configuration file.
The plug-in components are provided with configuration files after being acquired, the configuration files comprise a starting command, definable IP and port numbers, and each plug-in component is provided with a corresponding dependency library and plug-in code.
When executing the development imperative, when after finding the portal file, the local web service is started, the port number starts from 8080, and if a plurality of projects are developed simultaneously, +1 in turn, e.g., 8081.
When the packing command is executed, after the entry file is found, processing the index html of the entry file, identifying whether CDN introduction dependence is needed, calling a corresponding plug-in component and introducing needed CDN data into the head label if the CDN introduction dependence is needed, and calling the plug-in component to compress the picture after the CDN data is introduced, wherein the plug-in component is called to compress the picture if CDN is not needed.
Judging whether secondary compression is needed or not according to an execution command, if yes, compressing all picture data, then calling a plug-in component to process js files, otherwise, directly calling the plug-in component to process js files, then processing css files, after configuring a path of a resource referenced in the files, storing the picture data, js file data and css file data in a designated directory, and finally generating a read.md file of the project.
After executing the corresponding instruction command, the generated result is put into the designated directory through the designated output path or the storage path of the static resource.
The packing configuration has the main functions of merging, compressing and confusing source codes after the development is completed, packing the source codes into codes which can be identified and operated by a machine but are difficult to read by human beings, automatically creating a release catalog corresponding to the project after the packing is completed, and storing the products in the folder so as to be convenient for management and release.
When the package product is too large, the terminal prompts a warning.
Prompting whether the old file is clear, if so, cleaning, otherwise, reserving.
When the entry file is not found, reporting errors through the terminal, and prompting that the entry file is not found.
The entry file is index.
According to the embodiment, on the basis of the scaffold vite of the Vue framework, the public components and the resource data are placed in the appointed catalogue to serve as the public resources, a user can introduce the public components and the resource data in any position in the same mode, manual copying is avoided, the later maintenance cost is improved, all configuration and dependent packages in all projects are placed in the appointed catalogue to be uniformly managed, the scaffold and plug-in components are not required to be installed again after the projects are newly built, one execution command can be started, and time and space are reduced.
The present invention is not limited to the above-mentioned embodiments, and any changes or substitutions that can be easily understood by those skilled in the art within the technical scope of the present invention are intended to be included in the scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.