nw.js node-webkit series (18) how to compile .js to prevent your code from being exposed

This section will introduce how to compile the js code of your application and how to use the compiled file in your project.

(1) Compile

In the nw executable program directory, there is a nwjc.exe application program, which is used to compile .js files, please see the compilation command line:

nwjc source.js binary.bin

(2) use

To use the compiled .bin file in the application, use the following statement:

require('nw.gui').Window.get().evalNWBin(null, 'binary.bin');

(3) Demo

(1) Define a hello.js with a method named aa.

function aa(){
	alert("aa");
}

(2) Compile the hello.js file into a hello.bin file through the above method

(3) Use the hello.bin file and execute the aa method.

<script>
	require('nw.gui').Window.get().evalNWBin(null, 'hello.bin');
	aa();
</script>

(Note): The execution of the .bin file by the application is about 30% slower than the execution of the .js file.

(Note): The .bin files mentioned above are not common to all platforms. Different platforms can only execute .bin files generated using the command line on this platform.

Therefore, I do not recommend using the compiled .bin file as a means of encryption unless you must use it. If encryption is required, other encryption methods can be used to encrypt the .js file, that is, the application is still executing the .js.

Guess you like

Origin blog.csdn.net/zeping891103/article/details/50819102