CN109766099B - Front-end source code compiling method and device, storage medium and computer equipment - Google Patents

Front-end source code compiling method and device, storage medium and computer equipment Download PDF

Info

Publication number
CN109766099B
CN109766099B CN201811511759.0A CN201811511759A CN109766099B CN 109766099 B CN109766099 B CN 109766099B CN 201811511759 A CN201811511759 A CN 201811511759A CN 109766099 B CN109766099 B CN 109766099B
Authority
CN
China
Prior art keywords
code
file
dependency
end source
source code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201811511759.0A
Other languages
Chinese (zh)
Other versions
CN109766099A (en
Inventor
林法鑫
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Koubei Network Technology Co Ltd
Original Assignee
Zhejiang Koubei Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Koubei Network Technology Co Ltd filed Critical Zhejiang Koubei Network Technology Co Ltd
Priority to CN201811511759.0A priority Critical patent/CN109766099B/en
Publication of CN109766099A publication Critical patent/CN109766099A/en
Application granted granted Critical
Publication of CN109766099B publication Critical patent/CN109766099B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention discloses a front-end source code compiling method, a front-end source code compiling device, a storage medium and computer equipment, relates to the technical field of browsers, and mainly aims to realize that front-end source codes can be directly compiled locally in the browser, an extra compiling and constructing environment is not needed, a front-end development process can be simplified, and further the front-end development efficiency can be improved, wherein the method comprises the following steps: locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code; analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file. The invention is suitable for compiling the front-end source code.

Description

Front-end source code compiling method and device, storage medium and computer equipment
Technical Field
The present invention relates to the field of browser technologies, and in particular, to a front-end source code compiling method, device, storage medium, and computer apparatus.
Background
With the continuous development of information technology, in order to meet the work and life needs of people, browsers are more powerful, and various front-end pages can be displayed, and are generally realized by compiling front-end source codes for running the browsers.
Currently, an additional compile-build environment is usually needed to compile and build the front-end source code. However, the additional compiling and building environment is complex to build, and the using steps are complicated, so that the front-end development cost is high, and the development efficiency is reduced.
Disclosure of Invention
In view of this, the present invention provides a front-end source code compiling method, apparatus, storage medium and computer device, and mainly aims to implement directly compiling the front-end source code locally in a browser, without using an additional compiling and building environment, and simplify a front-end development process, thereby improving front-end development efficiency.
According to a first aspect of the present invention, there is provided a front-end source code compiling method, including:
locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code;
analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
Optionally, the analyzing, by using a loader built in the browser, a file code dependency relationship of the front-end source code, and compiling the front-end source code according to the file code dependency relationship and the dependency file include:
acquiring a first file code in the front-end source code, and acquiring a dependent file corresponding to the first file code from the dependent file;
compiling the first file code and a dependent file corresponding to the first file code by using a loader built in the browser to obtain a compiled code corresponding to the first file code;
inquiring a second file code depended by the first file code according to a code module specification of a compiled code corresponding to the first file code, wherein the code module specification stores a dependency relationship between the first file code and the second file code;
and performing operations of compiling and querying the file codes depended on the second file codes until the file codes in the front-end source codes are compiled.
Optionally, the compiling the first file code and the dependent file corresponding to the first file code by using a loader built in the browser to obtain a compiled code corresponding to the first file code includes:
searching a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, wherein different loaders are used for compiling file codes of different file types;
compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code.
Further, after the compiling the front-end source code according to the file code dependency relationship and the dependency file, the method further includes:
generating a compiled code dependency relationship graph according to the file code dependency relationship and the compiled code corresponding to the front-end source code;
and loading and running the compiled code corresponding to the front-end source code by utilizing a pre-simulated code loading environment and the compiled code dependency graph.
Optionally, the loading and running the compiled code corresponding to the front-end source code by using a pre-simulated code loading environment and the compiled code dependency graph includes:
loading a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment;
if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code;
and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code.
Optionally, the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code includes:
acquiring dependency package information sent by a dependency server;
searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address;
and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser.
Optionally, the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code includes:
sending a dependent file acquisition request to a proxy server, wherein the acquisition request carries dependent packet identification information corresponding to the front-end source code; the proxy server is used for downloading the dependency package corresponding to the front-end source code according to the dependency package identification information and decompressing to obtain a dependency file corresponding to the front-end source code;
and persistently caching the dependent file fed back by the dependent server in the local browser.
Optionally, the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code includes:
acquiring version information corresponding to the front-end source code;
and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code.
According to a second aspect of the present invention, there is provided a front-end source code compiling apparatus comprising:
the installation unit is used for locally installing a dependency package corresponding to the front-end source code in the browser to obtain a dependency file corresponding to the front-end source code;
and the compiling unit is used for analyzing the file code dependency relationship of the front-end source code by utilizing a loader built in the browser and compiling the front-end source code according to the file code dependency relationship and the dependency file.
Optionally, the compiling unit includes:
the acquisition module is used for acquiring a first file code in the front-end source code and acquiring a dependent file corresponding to the first file code from the dependent file;
the compiling module is used for compiling the first file code and the dependent file corresponding to the first file code by utilizing a loader arranged in the browser to obtain a compiled code corresponding to the first file code;
the query module is used for querying a second file code depended on by the first file code according to a code module specification of a compiled code corresponding to the first file code, and the code module specification stores a dependency relationship between the first file code and the second file code;
the compiling module is further configured to perform operations of compiling and querying the dependent file codes on the second file code until the file codes in the front-end source code are compiled.
Optionally, the compiling module is specifically configured to search a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, where different loaders are used to compile file codes of different file types; compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code.
Further, the apparatus further comprises:
the generating unit is used for generating a compiled code dependency relationship graph according to the file code dependency relationship and the compiled code corresponding to the front-end source code;
and the running unit is used for loading and running the compiled code corresponding to the front-end source code by utilizing a pre-simulated code loading environment and the compiled code dependency graph.
Optionally, the running unit is specifically configured to load a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment; if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code; and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code.
Optionally, the installation unit is specifically configured to obtain dependency package information sent by a dependency server; searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address; and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser.
Optionally, the installing unit is specifically configured to send a dependent file acquisition request to a proxy server, where the acquisition request carries dependency package identification information corresponding to the front-end source code; the proxy server is used for downloading the dependency package corresponding to the front-end source code according to the dependency package identification information and decompressing to obtain a dependency file corresponding to the front-end source code; and persistently caching the dependent file fed back by the dependent server in the local browser.
The installation unit is specifically configured to obtain version information corresponding to the front-end source code; and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code.
According to a third aspect of the present invention, there is provided a storage medium having at least one executable instruction stored therein, the executable instruction causing a processor to perform the steps of:
locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code;
analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
According to a fourth aspect of the present invention, there is provided a computer device comprising a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus, and the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to perform the following steps:
locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code;
analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
Compared with the method for compiling the front-end source code by an extra compiling and constructing environment, the method for compiling the front-end source code obtains the dependency file corresponding to the front-end source code by locally installing the dependency package corresponding to the front-end source code in the browser; the method comprises the steps of analyzing the dependency relationship of the file codes of the front-end source codes by using a loader built in the browser, compiling the front-end source codes according to the dependency relationship of the file codes and the dependency files, and directly compiling the front-end source codes locally in the browser, so that an environment is built without extra compiling, a front-end development process can be simplified, and the front-end development efficiency can be improved.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
fig. 1 is a schematic flowchart illustrating a front-end source code compiling method according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram illustrating a front-end source code compiling apparatus according to an embodiment of the present invention;
fig. 3 is a schematic structural diagram of another front-end source code compiling apparatus according to an embodiment of the present invention;
fig. 4 shows a physical structure diagram of a computer device according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
As described in the background, currently, an additional compile-build environment is usually required to compile and build the front-end source code. However, the additional compiling and building environment is complex to build, and the using steps are complicated, so that the front-end development cost is high, and the development efficiency is reduced.
In order to solve the above technical problem, an embodiment of the present invention provides a front-end source code compiling method, as shown in fig. 1, where the method includes:
101. and locally installing a dependency package corresponding to the front-end source code in the browser to obtain a dependency file corresponding to the front-end source code.
The front-end source code may be a code developed by using front-end development software, and specifically, the front-end source code may be a code developed by using javascript code language, an operating environment of the javascript development software is a node.js operating environment, and a code package management tool in the node.js operating environment may be npm, so that when the front-end source code is a javascript code, a npm dependent package may be locally installed in a browser. The dependency package may be a message body-parser (body-parser) dependency package, a cache-parser (cookie-parser) dependency package, a compilation (debug) dependency package, a template library (ejs) dependency package, a development framework (express) dependency package, a web tag request (service-facade) dependency package, a distributed document storage database (mongodb) dependency package, or the like. The dependency file obtained by installing the dependency package can be body-parser, cookie-parser, debug, ejs, express, serve-favicon, mongodb, and the like.
For the embodiment of the invention, the dependency package corresponding to the front-end source code is locally installed in the browser, so that the complete analysis and installation of the dependency package by the browser can be realized, the browser can provide the dependency resource required by the compilation or the operation of the front-end source code, and the front-end source code does not need to be converted into the operation environment corresponding to the front-end development software for compilation or operation. In addition, because the dependency file is stored in the local browser, when the dependency of the front-end source code is changed, the changed dependency file can be obtained without obtaining all the dependency files, so that the pressure of obtaining the dependency of the front-end source code can be reduced.
102. Analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
The front-end source code may include a plurality of file codes, and the file code dependency relationship may be a dependency relationship between the plurality of file codes, specifically, a reference relationship between file codes, and a file code may refer to a file code in the same package, or a file code across packages. For example, if file code 1 refers to file code 2 and file code 2 refers to file code 3, then there is a dependency between file code 1 and file code 2, and there is a dependency between file code 2 and file code 3. When the file code and other file codes have dependency relationship, the operation result of the file code needs to depend on the operation result of the other file codes.
It should be noted that the loader may be implemented according to a compilation project in a front-end development software operating environment corresponding to the front-end source code, for example, may be implemented according to a webpack compilation project in a node. Because the dependency relationship of the file codes is stored in the code module specification of the compiled codes corresponding to the file codes, the loader can be used for compiling the file codes in the front-end source codes to obtain the compiled codes corresponding to the file codes, then other file codes depended on by the file codes are searched according to the code module specification of the compiled codes corresponding to the file codes, and the steps are repeated on the other file codes depended on until the compiling of the whole front-end source codes is completed. For the embodiment of the invention, the front-end source code can be compiled directly in the local browser by realizing a loader mechanism in the browser environment, analyzing the file code dependency relationship of the front-end source code by using the loader mechanism and compiling the front-end source code according to the file code dependency relationship and the dependency file.
Compared with the method for compiling the front-end source code, which needs an extra compiling and constructing environment to compile and construct the front-end source code, the method for compiling the front-end source code obtains the dependency file corresponding to the front-end source code by locally installing the dependency package corresponding to the front-end source code in the browser; the method comprises the steps of analyzing the dependency relationship of the file codes of the front-end source codes by using a loader built in the browser, compiling the front-end source codes according to the dependency relationship of the file codes and the dependency files, and directly compiling the front-end source codes locally in the browser, so that an environment is built without extra compiling, a front-end development process can be simplified, and the front-end development efficiency can be improved.
Further, in order to better describe the process of the foregoing front-end source code compiling method, as a refinement and an extension to the foregoing embodiments, the embodiments of the present invention provide several alternative embodiments, but are not limited to this, and specifically as follows:
in an optional embodiment of the present invention, to implement direct compiling of the front-end source code in a browser, the step 102 may specifically include: acquiring a first file code in the front-end source code, and acquiring a dependent file corresponding to the first file code from the dependent file; compiling the first file code and a dependent file corresponding to the first file code by using a loader built in the browser to obtain a compiled code corresponding to the first file code; inquiring a second file code depended by the first file code according to a code module specification of a compiled code corresponding to the first file code, wherein the code module specification stores a dependency relationship between the first file code and the second file code; and performing operations of compiling and querying the file codes depended on the second file codes until the file codes in the front-end source codes are compiled. It should be noted that, by compiling the first file code, the obtained compiled code may be a code that conforms to the specification of a front-end development language code module, and for a javascript development language, the compiled code may be a code that conforms to the specification of a common. In addition, the process of compiling the file code and querying the file code that the file code depends on is repeated, and when the front-end source code is just compiled, the first file code may be an entry file code, specifically, a main file code, and the second file code may be a file code that the entry file code depends on. After compiling the entry file code, finding the file code depended on by the entry file code according to the code module specification of the compiled code of the entry file code, and then executing operations of compiling the file code and inquiring the file code depended on by the entry file code until all the file codes in the front-end source code are compiled.
In a specific application scenario, a loader may be selected to compile a file code according to a file type corresponding to the file code, and the compiling the first file code and a dependent file corresponding to the first file code by using the loader built in the browser to obtain a compiled code corresponding to the first file code may specifically include: searching a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, wherein different loaders are used for compiling file codes of different file types; compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code. The file type may be a picture type, a video type, an audio type, etc. For example, if the file type of the first file code is a picture type, a loader of the picture type may be searched from a loader built in the browser as a load for compiling the first file code. The file codes and the dependent files corresponding to the file codes are compiled by selecting the loader according to the file types of the file codes, so that the corresponding compiled codes can be ensured to conform to the front-end development language code module specification, and the compiling accuracy of the file codes can be ensured.
In another alternative embodiment of the present invention, in order to implement directly running the front-end source code in the browser and rendering a final front-end page of the browser, after the step 102, the method further includes: generating a compiled code dependency relationship graph according to the file code dependency relationship and the compiled code corresponding to the front-end source code; and loading and running the compiled code corresponding to the front-end source code by utilizing a pre-simulated code loading environment and the compiled code dependency graph. The compiled code dependency graph may be consistent with the file code dependency, for example, if the following file code dependency exists in the front-end source code: the file code 1 depends on the file code 2, the file code 2 depends on the file code 3, the file code 3 depends on the file code 4, the file code 4 does not depend on any file code, and a code dependency relationship graph after compiling is generated to show that: the compiled code corresponding to the file code 1 depends on the compiled code corresponding to the file code 2, the compiled code corresponding to the file code 2 depends on the compiled code corresponding to the file code 3, the compiled code corresponding to the file code 3 depends on the compiled code corresponding to the file code 4, and the file code 4 does not depend on any file code. The pre-simulated code loading environment may be realized by simulating a loading environment of front-end development software, and if the front-end source code is a javascript code, the pre-simulated code loading environment may be a common.
In a specific application scenario, the step of loading and running the compiled code corresponding to the front-end source code by using the pre-simulated code loading environment and the compiled code dependency graph may specifically include: loading a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment; if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code; and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code. The compiled code corresponding to the front-end source code is repeatedly loaded and run, when the compiled code corresponding to the front-end source code is just started to be loaded and run, the first compiled code may be a compiled code corresponding to an entry file code, specifically, a compiled code corresponding to a main file code, and the second compiled code may be a compiled code corresponding to a file code on which the entry file code depends. After the compiled code corresponding to the entry file code is loaded, the compiled code corresponding to the file code on which the entry file code depends is loaded, the step of loading the compiled code corresponding to the file code on which the entry file code depends is repeated until the compiled code corresponding to the front-end source code is loaded, and then all the loaded compiled codes are operated. For example, a compiled code dependency graph may exhibit: the compiled code corresponding to the file code 1 depends on the compiled code corresponding to the file code 2, the compiled code corresponding to the file code 2 depends on the compiled code corresponding to the file code 3, the compiled code corresponding to the file code 3 depends on the compiled code corresponding to the file code 4, and the file code 4 does not depend on any file code. When the compiled code is loaded and run, the compiled code corresponding to the file code 1 is loaded by using a common loading environment, then the compiled code corresponding to the file code 2 and the compiled code corresponding to the file code 3 are loaded, and finally the compiled code corresponding to the file code 4 is loaded, because the running of the file code 4 does not depend on any file code, the compiled code corresponding to the file code 4 is run, and after the compiled code corresponding to the file code 4 is run, the compiled code corresponding to the file code 3, the compiled code corresponding to the file code 2 and the compiled code corresponding to the file code 1 are run.
In yet another alternative embodiment of the present invention, the step 101 may specifically include: acquiring dependency package information sent by a dependency server; searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address; and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser. Specifically, an original code (tarball) field may be searched from the dependent packet information, the tarball field represents the dependent packet download address, the dependent packet generally exists in a compressed form, the dependent packet download address is pulled, the content of the download address is read in a byte stream manner, the dependent packet may be obtained, after the dependent packet is obtained, a preset decompression tool may be used to decompress the dependent packet corresponding to the front-end source code, and the preset decompression tool may be a gzip decompression tool or a tar decompression tool. In addition, in order to facilitate persistent storage of the decompressed dependent file in the local memory of the browser, the decompressed dependent file may be encapsulated in a browser encapsulation format (browser fs).
In addition, an embodiment of the present invention provides an optional manner for installing a dependency package corresponding to a front-end source code, where the step 101 may further include: sending a dependent file acquisition request to a proxy server, wherein the acquisition request carries dependent packet identification information corresponding to the front-end source code; the proxy server may be configured to download and decompress a dependency package corresponding to the front-end source code according to the dependency package identification information, so as to obtain a dependency file corresponding to the front-end source code; and persistently caching the dependent file fed back by the dependent server in the local browser. The proxy server can download the dependency package corresponding to the front-end source code by using a code package management tool in the running environment of the front-end development software, decompress the dependency package corresponding to the front-end source code, and issue the decompressed dependency file to the browser. Specifically, the proxy server may download the dependency package using the npm tool of the nodejs environment. The technical problem of cross-domain browser downloading can be solved by using the proxy server, and the browser can successfully download the dependent file.
In yet another alternative embodiment of the present invention, the step 101 may specifically include: acquiring version information corresponding to the front-end source code; and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code. It should be noted that, in order to make the front-end source code be continuous and complete, technicians usually continuously modify the front-end source code when developing the front-end source code, and therefore, there are usually multiple versions of the front-end source code, and by locally installing the dependency package corresponding to the front-end source code in the browser according to the version information, conflicts between the front-end source code and the installed dependency package can be avoided, so that normal compiling and running of the front-end source code can be ensured. For example, if the version corresponding to the front-end source code is version 1, installing the dependency package corresponding to the front-end source code of version 1 locally in the browser; and if the version corresponding to the front-end source code is version 2, locally installing a dependency package corresponding to the front-end source code of the version 2 in the browser.
Further, as a specific implementation of fig. 1, an embodiment of the present invention provides a front-end source code compiling apparatus, as shown in fig. 2, where the apparatus includes: a mounting unit 31 and a compiling unit 32.
The installation unit 31 is configured to locally install a dependency package corresponding to a front-end source code in a browser, so as to obtain a dependency file corresponding to the front-end source code. The installation unit 31 locally installs the dependency package corresponding to the front-end source code in the browser to obtain the function module of the dependency file corresponding to the front-end source code.
The compiling unit 32 is configured to analyze a file code dependency relationship of the front-end source code by using a loader built in the browser, and compile the front-end source code according to the file code dependency relationship and the dependency file. The compiling unit 32 is a functional module, which is also a core module, in the apparatus and analyzes the file code dependency of the front-end source code by using a loader built in the browser, and compiles the front-end source code according to the file code dependency and the dependency file.
In a specific application scenario, as shown in fig. 3, the compiling unit 32 may include: an obtaining module 321, a compiling module 322, and a query module 323.
The obtaining module 321 may be configured to obtain a first file code in the front-end source code, and obtain a dependent file corresponding to the first file code from the dependent file.
The compiling module 322 may be configured to compile the first file code and the dependent file corresponding to the first file code by using a loader built in the browser, so as to obtain a compiled code corresponding to the first file code.
The query module 323 may be configured to query, according to a code module specification of a compiled code corresponding to the first file code, a second file code on which the first file code depends, where the code module specification stores a dependency relationship between the first file code and the second file code.
The compiling module 322 may be further configured to perform operations of compiling and querying the file code dependent on the second file code until the file code in the front-end source code is compiled.
For the embodiment of the present invention, in order to ensure the accuracy of compiling the file code, a loader may be selected to compile the file code according to a file type, and the compiling module 322 is specifically configured to search a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, where different loaders are used to compile file codes of different file types; compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code.
For the embodiment of the present invention, in order to implement direct running of the compiled code corresponding to the front-end source code in the browser, the apparatus further includes: a generating unit 33 and an operating unit 34.
The generating unit 33 may be configured to generate a compiled code dependency graph according to the file code dependency and the compiled code corresponding to the front-end source code. The generating unit 33 is a functional module in the present apparatus that generates a compiled code dependency graph according to the file code dependency and the compiled code corresponding to the front-end source code.
The running unit 34 may be configured to load and run a compiled code corresponding to the front-end source code by using a pre-simulated code loading environment and the compiled code dependency graph. The running unit 34 is a functional module in the apparatus, which loads and runs the compiled code corresponding to the front-end source code by using a pre-simulated code loading environment and the compiled code dependency graph.
In a specific application scenario, the running unit 34 may be specifically configured to load a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment; if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code; and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code.
For the embodiment of the present invention, in order to implement the function of locally installing the dependency package corresponding to the front-end source code in the browser and obtaining the dependency file corresponding to the front-end source code, the installation unit 31 may be specifically configured to obtain the dependency package information sent by the dependency server; searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address; and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser.
The installing unit 31 may be further specifically configured to send a dependent file acquisition request to a proxy server, where the acquisition request carries dependent packet identification information corresponding to the front-end source code; the proxy server is used for downloading the dependency package corresponding to the front-end source code according to the dependency package identification information and decompressing to obtain a dependency file corresponding to the front-end source code; and persistently caching the dependent file fed back by the dependent server in the local browser.
For the embodiment of the present invention, in order to avoid the problem of version conflict between the front-end source code and the dependent package, the installation unit 31 may be further configured to specifically obtain version information corresponding to the front-end source code; and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code.
It should be noted that other corresponding descriptions of the functional modules related to the front-end source code compiling apparatus provided in the embodiment of the present invention may refer to the corresponding description of the method shown in fig. 1, and are not described herein again.
Based on the method shown in fig. 1, correspondingly, an embodiment of the present invention further provides a storage medium, where at least one executable instruction is stored in the storage medium, where the executable instruction causes a processor to perform the following steps: locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code; analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
Based on the above-mentioned embodiments of the method shown in fig. 1 and the apparatus shown in fig. 2, the embodiment of the present invention further provides a computer device, as shown in fig. 4, including a processor (processor)41, a communication Interface (communication Interface)42, a memory (memory)43, and a communication bus 44. Wherein: the processor 41, the communication interface 42, and the memory 43 communicate with each other via a communication bus 44. A communication interface 44 for communicating with network elements of other devices, such as clients or other servers. The processor 41 is configured to execute a program, and may specifically execute relevant steps in the above data conversion method embodiment. In particular, the program may include program code comprising computer operating instructions. The processor 41 may be a central processing unit CPU or an application Specific integrated circuit asic or one or more integrated circuits configured to implement embodiments of the present invention.
The terminal comprises one or more processors, which can be the same type of processor, such as one or more CPUs; or may be different types of processors such as one or more CPUs and one or more ASICs. And a memory 43 for storing a program. The memory 43 may comprise a high-speed RAM memory, and may further include a non-volatile memory (non-volatile memory), such as at least one disk memory. The program may specifically be adapted to cause the processor 41 to perform the following operations: locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code; analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file.
According to the technical scheme, the dependency package corresponding to the front-end source code can be locally installed in the browser, and the dependency file corresponding to the front-end source code is obtained; the method comprises the steps of analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file, so that the front-end source code can be directly compiled in the local browser, an environment is built without additional compiling, the front-end development process can be simplified, and the front-end development efficiency can be improved.
In the foregoing embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
It will be appreciated that the relevant features of the method and apparatus described above are referred to one another. In addition, "first", "second", and the like in the above embodiments are for distinguishing the embodiments, and do not represent merits of the embodiments.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The algorithms and displays presented herein are not inherently related to any particular computer, virtual machine, or other apparatus. Various general purpose systems may also be used with the teachings herein. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
The various component embodiments of the invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It will be appreciated by those skilled in the art that a microprocessor or Digital Signal Processor (DSP) may be used in practice to implement some or all of the functions of some or all of the components in a front-end source code compilation apparatus according to embodiments of the present invention. The present invention may also be embodied as apparatus or device programs (e.g., computer programs and computer program products) for performing a portion or all of the methods described herein. Such programs implementing the present invention may be stored on computer-readable media or may be in the form of one or more signals. Such a signal may be downloaded from an internet website or provided on a carrier signal or in any other form.
It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention may be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.

Claims (18)

1. A front-end source code compiling method, comprising:
locally installing a dependency package corresponding to a front-end source code in a browser to obtain a dependency file corresponding to the front-end source code;
analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser, and compiling the front-end source code according to the file code dependency relationship and the dependency file, wherein the file code dependency relationship is the dependency relationship or reference relationship among a plurality of file codes included in the front-end source code.
2. The method of claim 1, wherein analyzing, by a loader built in the browser, file code dependencies of the front-end source code and compiling the front-end source code according to the file code dependencies and the dependency files comprises:
acquiring a first file code in the front-end source code, and acquiring a dependent file corresponding to the first file code from the dependent file;
compiling the first file code and a dependent file corresponding to the first file code by using a loader built in the browser to obtain a compiled code corresponding to the first file code;
inquiring a second file code depended by the first file code according to a code module specification of a compiled code corresponding to the first file code, wherein the code module specification stores a dependency relationship between the first file code and the second file code;
and performing operations of compiling and querying the file codes depended on the second file codes until the file codes in the front-end source codes are compiled.
3. The method according to claim 2, wherein the compiling the first file code and the dependent file corresponding to the first file code by using a loader built in the browser to obtain a compiled code corresponding to the first file code comprises:
searching a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, wherein different loaders are used for compiling file codes of different file types;
compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code.
4. The method of claim 1, wherein after compiling the front-end source code according to the file code dependencies and the dependency file, the method further comprises:
generating a compiled code dependency relationship graph according to the file code dependency relationship and the compiled code corresponding to the front-end source code, wherein the compiled code dependency relationship graph is consistent with the file code dependency relationship, and the compiled code dependency relationship graph shows that the compiled code corresponding to the file code depends on the compiled code corresponding to the file code with the dependency relationship with the file code;
and loading and running the compiled code corresponding to the front-end source code by utilizing a pre-simulated code loading environment and the compiled code dependency graph.
5. The method of claim 4, wherein the loading and running the compiled code corresponding to the front-end source code by using the pre-simulated code loading environment and the compiled code dependency graph comprises:
loading a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment;
if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code;
and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code.
6. The method according to claim 1, wherein the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code comprises:
acquiring dependency package information sent by a dependency server;
searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address;
and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser.
7. The method according to claim 1, wherein the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code comprises:
sending a dependent file acquisition request to a proxy server, wherein the acquisition request carries dependent packet identification information corresponding to the front-end source code; the proxy server is used for downloading the dependency package corresponding to the front-end source code according to the dependency package identification information and decompressing to obtain a dependency file corresponding to the front-end source code;
and persistently caching the dependent file fed back by the proxy server in the local browser.
8. The method according to claim 1, wherein the locally installing the dependency package corresponding to the front-end source code in the browser to obtain the dependency file corresponding to the front-end source code comprises:
acquiring version information corresponding to the front-end source code;
and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code.
9. A front-end source code compiling apparatus comprising:
the installation unit is used for locally installing a dependency package corresponding to the front-end source code in the browser to obtain a dependency file corresponding to the front-end source code;
and the compiling unit is used for analyzing the file code dependency relationship of the front-end source code by using a loader built in the browser and compiling the front-end source code according to the file code dependency relationship and the dependency file, wherein the file code dependency relationship is the dependency relationship or the reference relationship among a plurality of file codes included in the front-end source code.
10. The apparatus of claim 9, wherein the compiling unit comprises:
the acquisition module is used for acquiring a first file code in the front-end source code and acquiring a dependent file corresponding to the first file code from the dependent file;
the compiling module is used for compiling the first file code and the dependent file corresponding to the first file code by utilizing a loader arranged in the browser to obtain a compiled code corresponding to the first file code;
the query module is used for querying a second file code depended on by the first file code according to a code module specification of a compiled code corresponding to the first file code, and the code module specification stores a dependency relationship between the first file code and the second file code;
the compiling module is further configured to perform operations of compiling and querying the dependent file codes on the second file code until the file codes in the front-end source code are compiled.
11. The apparatus of claim 10,
the compiling module is specifically configured to search a loader corresponding to the first file code from a loader built in the browser according to the file type of the first file code, and different loaders are used for compiling file codes of different file types; compiling the first file code and the dependent file corresponding to the first file code by using the searched loader to obtain a compiled code corresponding to the first file code.
12. The apparatus of claim 9, further comprising:
the generating unit is used for generating a compiled code dependency relationship graph according to the file code dependency relationship and the compiled code corresponding to the front-end source code, wherein the compiled code dependency relationship graph is consistent with the file code dependency relationship, and the compiled code dependency relationship graph shows that the compiled code corresponding to the file code depends on the compiled code corresponding to the file code with the dependency relationship with the file code;
and the running unit is used for loading and running the compiled code corresponding to the front-end source code by utilizing a pre-simulated code loading environment and the compiled code dependency graph.
13. The apparatus of claim 12,
the running unit is specifically configured to load a first compiled code in the compiled codes corresponding to the front-end source code by using a pre-simulated code loading environment; if a second compiled code which the first compiled code depends on exists in the compiled code dependency relationship diagram, loading the second compiled code; and if a second compiled code which is depended by the first compiled code does not exist in the compiled code dependency relationship graph, running the first compiled code.
14. The apparatus of claim 9,
the installation unit is specifically used for acquiring the dependency package information sent by the dependency server; searching a download address of the dependency package corresponding to the front-end source code from the dependency package information, and downloading the dependency package corresponding to the front-end source code according to the download address; and decompressing the dependency package corresponding to the front-end source code, and persistently storing the decompressed dependency file in the local browser.
15. The apparatus of claim 9,
the installation unit is specifically configured to send a dependent file acquisition request to a proxy server, where the acquisition request carries dependency package identification information corresponding to the front-end source code; the proxy server is used for downloading the dependency package corresponding to the front-end source code according to the dependency package identification information and decompressing to obtain a dependency file corresponding to the front-end source code; and persistently caching the dependent file fed back by the proxy server in the local browser.
16. The apparatus of claim 9,
the installation unit is specifically configured to obtain version information corresponding to the front-end source code; and locally installing the dependency package corresponding to the front-end source code in the browser according to the version information to obtain a dependency file corresponding to the front-end source code.
17. A storage medium having a computer program stored thereon, the storage medium having at least one executable instruction stored therein, the executable instruction causing a processor to perform operations corresponding to the front-end source code compiling method according to any one of claims 1 to 8.
18. A computer device comprising a processor, a memory, a communication interface, and a communication bus, wherein the processor, the memory, and the communication interface communicate with each other via the communication bus, and the memory is used for storing at least one executable instruction, and the executable instruction causes the processor to perform an operation corresponding to the front-end source code compiling according to any one of claims 1 to 8.
CN201811511759.0A 2018-12-11 2018-12-11 Front-end source code compiling method and device, storage medium and computer equipment Active CN109766099B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811511759.0A CN109766099B (en) 2018-12-11 2018-12-11 Front-end source code compiling method and device, storage medium and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811511759.0A CN109766099B (en) 2018-12-11 2018-12-11 Front-end source code compiling method and device, storage medium and computer equipment

Publications (2)

Publication Number Publication Date
CN109766099A CN109766099A (en) 2019-05-17
CN109766099B true CN109766099B (en) 2020-07-31

Family

ID=66451765

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811511759.0A Active CN109766099B (en) 2018-12-11 2018-12-11 Front-end source code compiling method and device, storage medium and computer equipment

Country Status (1)

Country Link
CN (1) CN109766099B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111176625B (en) * 2019-12-31 2023-07-28 杭州趣链科技有限公司 Method for efficiently compiling intelligent contract of solubility at browser end
CN112068842A (en) * 2020-09-15 2020-12-11 贝壳技术有限公司 Dependency relationship establishing method, linkage compiling method and system
CN112363699B (en) * 2020-11-16 2022-08-02 佳都科技集团股份有限公司 Interaction method and device applied to multi-language development platform
CN113721916B (en) * 2021-07-29 2023-07-14 苏州浪潮智能科技有限公司 Compiling method, device and equipment of operating system and readable storage medium
CN113805874A (en) * 2021-09-10 2021-12-17 上海得帆信息技术有限公司 Front-end code fragment dynamic rendering method and system suitable for multi-frame language
CN114760355B (en) * 2022-03-18 2023-09-26 麒麟软件有限公司 Node. Js dependent offline management method
CN117251165A (en) * 2023-08-24 2023-12-19 上海合芯数字科技有限公司 Method, device, terminal and medium for compiling building

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833449A (en) * 2010-04-16 2010-09-15 中山大学 Compile processing method and system based on cloud computing
CN107547944A (en) * 2016-06-27 2018-01-05 中兴通讯股份有限公司 Interface realizing method and device, set top box
CN108874399A (en) * 2017-05-11 2018-11-23 龙芯中科技术有限公司 The method, apparatus and terminal of plug-in unit are installed

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170329767A1 (en) * 2016-05-10 2017-11-16 International Business Machines Corporation Localization of application user interface
US10268460B2 (en) * 2017-01-25 2019-04-23 Walmart Apollo, Llc Systems, method, and non-transitory computer-readable storage media for generating code for displaying a webpage
US10691577B2 (en) * 2017-03-03 2020-06-23 Snyk Limited Identifying flawed dependencies in deployed applications
CN108804159B (en) * 2018-06-14 2022-02-18 腾讯科技(深圳)有限公司 Javascript module loading method and preprocessing method and device thereof, and computer equipment

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101833449A (en) * 2010-04-16 2010-09-15 中山大学 Compile processing method and system based on cloud computing
CN107547944A (en) * 2016-06-27 2018-01-05 中兴通讯股份有限公司 Interface realizing method and device, set top box
CN108874399A (en) * 2017-05-11 2018-11-23 龙芯中科技术有限公司 The method, apparatus and terminal of plug-in unit are installed

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
Java web 开发的设计与实现;王 然;《民营科技》;20131231;全文 *

Also Published As

Publication number Publication date
CN109766099A (en) 2019-05-17

Similar Documents

Publication Publication Date Title
CN109766099B (en) Front-end source code compiling method and device, storage medium and computer equipment
CN108037961B (en) Application program configuration method, device, server and storage medium
US9811360B2 (en) Dynamic determination of application server runtime classloading
US10599413B2 (en) Method and device for identifying file
CN110673853B (en) Compiling method, device and system
CN111680253B (en) Page application data packet generation method and device, computer equipment and storage medium
CN108279941B (en) Application program compression method and device
CN111427579A (en) Plug-in, application program implementing method and system, computer system and storage medium
CN110895471A (en) Installation package generation method, device, medium and electronic equipment
CN115686606A (en) Method, device, system and medium for displaying item dependency tree
CN111596951A (en) Method and device for configuring engineering file
CN107608672B (en) UI module manager, UI module management method and system
KR20110130611A (en) Web platform unit for mobile terminal connectioned web-application program in heterogeneous operating system
CN110928545B (en) Component distribution method, development method and device of single-page application and storage medium
CN114490103A (en) Operating system interface calling method and device and electronic equipment
CN112631563A (en) System development method and device based on framework, computer equipment and storage medium
CN111880786A (en) Multi-application sharing method, system, device, electronic equipment and storage medium
CN113761412A (en) Application page display method and device, electronic equipment, medium and application system
CN110968339A (en) Method and device for front-end construction tool and electronic equipment
CN116302054A (en) Development method and device of software project, storage medium and electronic equipment
CN113568623A (en) Application deployment method and device and electronic equipment
CN110489124B (en) Source code execution method, source code execution device, storage medium and computer equipment
CN111273940B (en) Method and device for uploading program file to code warehouse
CN113568678A (en) Method and device for dynamically loading resources and electronic equipment
CN112269602A (en) WebAssembly loading method and device and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant