Home

Awesome

nw-builder

npm Join the chat at https://gitter.im/nwjs/nw-builder

Build NW.js applications for Mac, Windows and Linux.

Major Features

Table of Contents

Install

npm i -D nw-builder

Every NW.js release includes a modified Node.js binary at a specific version. It is recommended to install exactly that version on the host system. Not doing so may download ABI incompatible Node modules. Consult the NW.js versions manifest for what Node.js version to install. It is recommended to use a Node version manager (such as volta, n, nvm, or nvm-windows) to be able to easily install and switch between Node versions.

Usage

This package can be used via a command line interface, be imported as a JavaScript module, or configured via the Node manifest as a JSON object. If options are defined in Node manifest, then they will be used over options defined in CLI or JavaScript API.

CLI interface:

nwbuild --mode=build --glob=false --flavor=sdk --cacheDir=./node_modules/nw /path/to/project

ESM import:

import nwbuild from "nw-builder";

CJS import:

let nwbuild;
import("nwbuild")
  .then((object) => {
    nwbuild = obj;
  })
  .catch((error) => {
    console.error(error);
  });

nwbuild({
  mode: "build",
  glob: false,
  flavor: "sdk",
  cacheDir: "./node_modules/nw",
  srcDir: "/path/to/project",
});

Node manifest usage:

{
    "nwbuild": {
      "mode": "build",
      "glob": false,
      "flavor": "sdk",
      "cacheDir": "./node_modules/nw",
      "srcDir": "/path/to/project"
    }
}

See nw-builder in action by building the demo application.

  1. git clone https://github.com/nwutils/nw-builder
  2. Run npm run demo:bld:linux && npm run demo:exe:linux to build and execute a Linux application.
  3. Run npm run demo:bld:osx && npm run demo:exe:osx to build and execute a MacOS application.
  4. Run npm run demo:bld:win && npm run demo:exe:win to build and execute a Windows application.

From here on we will show nw-builder functionality by using the JavaScript module. Please note that the same functionality applies when using a command line or manifest file.

Concepts

nw-builder can get, run and build NW.js applications. We refer to them as get, run and build modes.

Get Mode

Deprecation warning: From v4.6.4 onward, get mode is deprecated. This logic has been ported over to nwjs/npm-installer repo and will be removed in the next major release.

By default you get the normal build of the latest NW.js release for your specific platform and arch. For more information, please refer to the API reference.

nwbuild({
  mode: "get"
});

Get the community built FFmeg which contains proprietary codecs. This options is disabled by default. Please read the license's constraints before enabling this option.

nwbuild({
  mode: "get",
  ffmpeg: true
});

Get Node headers if you have to rebuild Node addons.

nwbuild({
  mode: "get",
  nativeAddon: "gyp"
});

Run Mode

Deprecation warning: From v4.6.0 onward, run mode is deprecated. This logic has been ported over to nwjs/npm-installer repo and will be removed in the next major release.

const nwProcess = await nwbuild({
  mode: "run",
  srcDir: "./app",
  glob: false,
});

Note: The nwProcess is a Node.js process

Build Mode

Build with defaults:

nwbuild({
  mode: "build",
});

Managed Manifest

You can let nw-builder manage your node modules. The managedManifest options accepts a boolean, string or object type. It will then remove devDependencies, autodetect and download dependencies via the relevant packageManager. If none is specified, it uses npm as default.

Setting it to true will parse the first Node manifest it encounters as the NW manifest.

nwbuild({
  mode: "build",
  managedManifest: true,
});

Setting it to a string implies that you are passing the file path to the NW manifest.

nwbuild({
  mode: "build",
  managedManifest: "./nw.js",
});

Setting it to a object implies you are directly passing the NW manifest as a JavaScript object.

nwbuild({
  mode: "build",
  managedManifest: {
    name: "nwdemo",
    main: "index.html"
  },
});

Rebuild Node addons

Currently this feature is quite limited. It only builds node addons which have a binding.gyp file in the srcDir. There are plans to support nan, cmake, ffi and gn and auto rebuild native addons which are installed as node modules.

nwbuild({
  mode: "build",
  nodeAddon: "gyp",
});

We recommend rebuilding Node addons for NW.js via node-gyp if you are using NW.js v0.83.0 or above.

node-gyp rebuild --target=22.2.0 --nodedir=/path/to/nw/node/headers

NW.js's Node version should match the Node version on the host machine due to ABI differences in V8.

API Reference

Options

NameTypeDefaultDescription
mode"get" | "run" | "build""build"Choose between get, run or build mode
versionstring | "latest" | "stable""latest"Runtime version
flavor"normal" | "sdk""normal"Runtime flavor
platform"linux" | "osx" | "win"Host platform
arch"ia32" | "x64" | "arm64"Host architecture
downloadUrl"https://dl.nwjs.io" | "https://npm.taobao.org/mirrors/nwjs" | https://npmmirror.com/mirrors/nwjs | "https://github.com/corwin-of-amber/nw.js/releases/""https://dl.nwjs.io"Download server. Supports file systems too (for example file:///home/localghost/nwjs_mirror)
manifestUrl"https://nwjs.io/versions" | "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json""https://nwjs.io/versions"Versions manifest
cacheDirstring"./cache"Directory to cache NW binaries
cachebooleantrueIf true the existing cache is used. Otherwise it removes and redownloads it.
ffmpegbooleanfalseIf true the chromium ffmpeg is replaced by community version with proprietary codecs.
logLevel"error" | "warn" | "info" | "debug""info"Specify level of logging.
srcDirstring"./"File paths to application code
argvstring[][]Command line arguments to pass to NW executable in run mode. You can also define these in chromium-args in NW.js manifest.
globbooleantrueIf true file globbing is enabled when parsing srcDir.
outDirstring"./out"Directory to store build artifacts
managedManifestboolean | string | objectfalseManaged manifest
nodeAddonfalse | "gyp"falseRebuild Node native addons
zipboolean | "zip" | "tar" | "tgz"falseIf true, "zip", "tar" or "tgz" the outDir directory is compressed.
appLinuxRc | WinRc | OsxRcAdditional options for each platform. (See below.)

app configuration object

This object defines additional properties used for building for a specific platform. For each platform, pass an object with appropriate values:

Windows-specific options (WinRc)

NameTypeDefaultDescription
iconstringundefinedThe path to the icon file. It should be a .ico file. (WARNING: Please define the icon in the NW.js manifest instead)
namestringValue of name in NW.js manifestThe name of the application
versionstringValue of version in NW.js manifestThe version of the application
commentsstringundefinedAdditional information that should be displayed for diagnostic purposes.
companystringValue of author in NW.js manifestCompany that produced the file—for example, Microsoft Corporation or Standard Microsystems Corporation, Inc. This string is required.
fileDescriptionstringValue of description in NW.js manifestFile description to be presented to users. This string may be displayed in a list box when the user is choosing files to install. For example, Keyboard Driver for AT-Style Keyboards. This string is required.
fileVersionstringValue of version or value of version in NW.js manifestVersion number of the file. For example, 3.10 or 5.00.RC2. This string is required.
internalNamestringValue of name in NW.js manifestInternal name of the file, if one exists—for example, a module name if the file is a dynamic-link library. If the file has no internal name, this string should be the original filename, without extension. This string is required.
legalCopyrightstringundefinedCopyright notices that apply to the file. This should include the full text of all notices, legal symbols, copyright dates, and so on. This string is optional.
legalTrademarkstringundefinedTrademarks and registered trademarks that apply to the file. This should include the full text of all notices, legal symbols, trademark numbers, and so on. This string is optional.
originalFilenamestringValue of name optionOriginal name of the file, not including a path. This information enables an application to determine whether a file has been renamed by a user. The format of the name depends on the file system for which the file was created. This string is required.
privateBuildstringundefinedInformation about a private version of the file—for example, Built by TESTER1 on \TESTBED.
productNamestringname in NW.js manifestName of the product with which the file is distributed. This string is required.
productVersionstringValue of version in NW.js manifestVersion of the product with which the file is distributed—for example, 3.10 or 5.00.RC2.
specialBuildstringundefinedText that specifies how this version of the file differs from the standard version—for example, Private build for TESTER1 solving mouse problems on M250 and M250E computers.
languageCodenumber1033Language of the file, defined by Microsoft, see: https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a

Linux-specific options (LinuxRc)

NameTypeDescription
namestringName of the application
genericNamestringGeneric name of the application
noDisplaybooleanIf true the application is not displayed
commentstringTooltip for the entry, for example "View sites on the Internet".
iconstringIcon to display in file manager, menus, etc. (WARNING: Please define the icon in the NW.js manifest instead)
hiddenbooleanTBD
onlyShowInstring[]A list of strings identifying the desktop environments that should display a given desktop entry
notShowInstring[]A list of strings identifying the desktop environments that should not display a given desktop entry
dBusActivatablebooleanA boolean value specifying if D-Bus activation is supported for this application
tryExecstringPath to an executable file on disk used to determine if the program is actually installed
execstringProgram to execute, possibly with arguments.
pathstringIf entry is of type Application, the working directory to run the program in.
terminalbooleanWhether the program runs in a terminal window.
actionsstring[]Identifiers for application actions.
mimeTypestring[]The MIME type(s) supported by this application.
categoriesstring[]Categories in which the entry should be shown in a menu
implementsstring[]A list of interfaces that this application implements.
keywordsstring[]A list of strings which may be used in addition to other metadata to describe this entry.
startupNotifybooleanIf true, it is KNOWN that the application will send a "remove" message when started with the DESKTOP_STARTUP_ID environment variable set. If false, it is KNOWN that the application does not work with startup notification at all.
startupWMClassstringIf specified, it is known that the application will map at least one window with the given string as its WM class or WM name hin
prefersNonDefaultGPUbooleanIf true, the application prefers to be run on a more powerful discrete GPU if available.
singleMainWindowstringIf true, the application has a single main window, and does not support having an additional one opened.

MacOS-specific options (OsxRc)

NameTypeDescription
namestringThe name of the application
iconstringThe path to the icon file. It should be a .icns file. (WARNING: Please define the icon in the NW.js manifest instead)
LSApplicationCategoryTypestringThe category that best describes your app for the App Store.
CFBundleIdentifierstringA unique identifier for a bundle usually in reverse DNS format.
CFBundleNamestringA user-visible short name for the bundle.
CFBundleDisplayNamestringThe user-visible name for the bundle.
CFBundleSpokenNamestringA replacement for the app name in text-to-speech operations.
CFBundleVersionstringThe version of the build that identifies an iteration of the bundle.
CFBundleShortVersionStringstringThe release or version number of the bundle.
NSHumanReadableCopyrightstringA human-readable copyright notice for the bundle.
NSLocalNetworkUsageDescriptionstringA human-readable description of why the application needs access to the local network.

Guides

Get unofficial MacOS builds

If you're running older Apple machines, you can download the unofficial builds.

Note: You will have to manually remove quarantine flag.

sudo xattr -r -d com.apple.quarantine /path/to/nwjs.app
nwbuild({
  mode: "get",
  platform: "osx",
  arch: "arm64",
  downloadUrl: "https://github.com/corwin-of-amber/nw.js/releases/download",
  manifestUrl: "https://raw.githubusercontent.com/nwutils/nw-builder/main/src/util/osx.arm.versions.json",
});

Note: Community FFmpeg binaries may not be available for unofficial builds. You will have to rebuild them yourself.

Get binaries via mirrors

China mirror:

nwbuild({
  mode: "get",
  downloadUrl: "https://npm.taobao.org/mirrors/nwjs",
});

Singapore mirror:

nwbuild({
  mode: "get",
  downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
});

Let nw-builder manage your native addons

Note: this behaviour is buggy and quite limited. This guide is to show what will be possible in the coming minor releases.

nwbuild({
  mode: "build",
  managedManifest: true,
  nativeAddon: "gyp",
});

Contributing

External contributor

Maintainer guidelines

Roadmap

Bugs

Features

Chores

FAQ

License

MIT License.