How to package a NW.js application on Windows

William picture William · Jun 6, 2016 · Viewed 9.7k times · Source

I am reading the instructions for how to package a NW.js app and the wording is a confusing mess and makes no sense. I highlighted the contradictory word-salad parts.

Create a zip file (this is built into XP, Vista and 7) Copy all of your files into the zip file, retaining directory structure and making sure that the package.json file is in the root directory (if you make a zip file containing a folder with your stuff in it, then it's not going to work) Rename the file extension from .zip to .nw. By default, file extensions may be hidden. You need to (press alt), go to folder options and uncheck "Hide extensions for known file types" to be able to rename the zip.

Is there a simple step by step instruction set for how to do this ? I looked online and couldn't find any for Windows OS. The goal is to create an executable file ( .exe ) with the innards of the application hidden from users.

I've done it on Mac before but never windows. The way the official documentation is written is just too confusing and all over the place for me to understand.

Answer

Mikhail picture Mikhail · Jun 6, 2016

For this purpose, you can use https://github.com/nwjs/nw-builder

Lets you build your NW.js apps for mac, win and linux via cli. It will download the prebuilt binaries for a newest version, unpacks it, creates a release folder, create the app.nw file for a specified directory and copies the app.nw file where it belongs.

First of all, install the node-webkit-builder module globally using:

$ npm install node-webkit-builder -g

Once the module has been installed, you can run the nwbuild command as follows:

$ nwbuild [options] [path]

Whereas path is the path to your project folder, options are the ones described in the following code:

-p Operating System to build ['osx32', 'osx64', 'win32', 'win64']
-v NW.js version [default: "latest"]
-r Runs NW.js project [default: false]
-o The path of the output folder [default: "./build"]
-f Force download of node-webkit [default: false]
--quiet Disables logging

Some examples:

  1. Run a project (on the current platform):

    $ nwbuild -v [version of your nw.js] -r /path/to/the/project
    
  2. Build a project (executable file ( .exe )) for Win32 or/and Win64 platforms:

    $ nwbuild -v [version of your nw.js] -p win32,win64 /path/to/the/project
    

If your cmd currently open in the project folder, instread write full path to your project you can just use dot symbol