Use node-webkit to package web applications into desktop applications (windows environment) and node-webkitweb

Source: Internet
Author: User

Use node-webkit to package web applications into desktop applications (windows environment) and node-webkitweb

Node-webkit is a Chromium and node. js combination, through which we can build on the chrome browser and node. web applications on js can be packaged into desktop applications and can also be cross-platform. Obviously, compared with traditional desktop applications, web applications developed using html5 + css3 + js in some specific fields are simpler and more efficient, and node can also be used. js functions, so node-webkit is very useful.

Next I will use a simple demo to introduce how to package a web application into an executable file (here I will only introduce the windows environment)

First, create an index.html file. As the portal page of our demo, we will treat this page as a complete web application. The content can be written at will, for example:

Create the configuration file package. json with the following content:

The main attribute is used to specify the entry file. The value of this attribute can be a local file or a remote URL, this is equivalent to directly converting a remote web application into a desktop application.

In addition to the name and main attributes, there are many other useful attributes that can be configured, such as specifying the application icon, displaying the toolbar of the browser, and specifying the initial size of the browser, specific Configuration Parameter documentation can see here https://github.com/rogerwang/node-webkit/wiki/Manifest-format

Now we have two files.

After that, compress the two files index.html and package.jsoninto A zipzip package named app.zip.

Now the content in the compressed package app.zip should be like this:

Then change the extension of the app.zip file to nw to app. nw.

Download a node-webkit for windows and decompress it to get a folder:

The app.nwfile we obtained earlier can be executed with n1_exe, and we can directly drag app.nwto nw.exe. The running result is as follows:

The effect of hitting the index.html page in chromeis is similar. Of course, you can configure the package. json file to hide the toolbar or border of the browser and make it more like a desktop software.

Because the running of the nw file requires support from the node-webkit environment, we also need to package the app. nw file together with the node-webkit environment file into an executable file.

First open windows cmd, and then enter the following command:

Copy/B nw.exe + app. nw app.exe

Secret will also be in this folder.

After executing the command, we get the executable file app.exe.

At this point, we have obtained the app.exefile, but if only the app.exe file is not enough, the execution of this executable file requires support for several dll files.

The nw. pak and icudt. dll files are required.

The ffmpegsumo. dll file is a media support file. If you use <video> or <audio> or other media-related content on your html page, you must include this file.

LibEGL. dll and libGLESv2.dll are required to use webGL or GPU.

Finally, we get a folder like this:

Execute app.exe to run our demo.

However, most of us want to give the user an exe file, and the user can use it without additional files.

Then, we can package app.exe and other files again and convert all the files into an executable file. As long as you get this file, you can run our application.

In this step, we need a software called Enigma Virtual Box. First download and install the software, and then open it.

Then Input the path of our app.exe in Enter Input File nameand Enter the path where we want to Output the packaged executable File in Enter Output File Name. The last step is to drag other Files except app.exe to Files. If you encounter any prompts, you can use the default setting.

Click the Process button in the lower-right corner.

Finally, we get an app_boxed.exe file. You only need to hand it over to the user and the user can run it.

Although node-webkit is convenient, a major drawback is that the executable file is a little large. You can decide not to use it after measuring the pros and cons.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.