Build NW.js applications for Linux, MacOS and Windows
Build NW.js applications for Mac, Windows and Linux.
For version 3, please go to the corresponding branch.
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.
For example, NW.js v0.83.0 comes with Node.js v21.1.0.
$: node --version
v21.1.0
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.
ESM import:
import nwbuild from "nw-builder";
CJS import:
let nwbuild;
import("nwbuild")
.then((object) => {
nwbuild = obj;
})
.catch((error) => {
console.error(error);
});
Node manifest usage:
{
"nwbuild": {
// user specified options
}
}
From here on we will show
nw-builder
functionality by using the JavaScript module. Please note that the same method applies when using a command line or Node manifest.
nw-builder
can get, run and build NW.js applications. We refer to them as get, run and build modes.
Deprecation warning: From v4.6.4 onward, run mode is deprecated. This logic will be ported over to nwjs/npm-installer repo and 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"
});
Deprecation warning: From v4.6.0 onward, run mode is deprecated. This logic will be ported over to
nwjs/npm-installer
repo and removed in the next major release.
nwbuild({
mode: "run",
srcDir: "./app",
glob: false,
});
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=21.1.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.
Options
Name | Type | Default | Description |
---|---|---|---|
mode | "get" | "run" | "build" |
"build" |
Choose between get, run or build mode |
version | string | "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 |
cacheDir | string |
"./cache" |
Directory to cache NW binaries |
srcDir | string |
"./" |
File paths to application code |
outDir | string |
"./out" |
Directory to store build artifacts |
managedManifest | boolean | string | object |
false |
Managed manifest |
nodeAddon | false | "gyp" |
false |
Rebuild Node native addons |
cache | boolean |
true |
If true the existing cache is used. Otherwise it removes and redownloads it. |
ffmpeg | boolean |
false |
If true the chromium ffmpeg is replaced by community version with proprietary codecs. |
glob | boolean |
true |
If true file globbing is enabled when parsing srcDir . |
logLevel | "error" | "warn" | "info" | "debug" |
"info" |
Specify level of logging. |
zip | boolean | "zip" | "tar" | "tgz" |
false |
If true, "zip", "tar" or "tgz" the outDir directory is compressed. |
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.
China mirror:
nwbuild({
mode: "get",
downloadUrl: "https://npm.taobao.org/mirrors/nwjs",
});
Singapore mirror:
nwbuild({
mode: "get",
downloadUrl: "https://cnpmjs.org/mirrors/nwjs/",
});
nw-builder
manage your native addonsNote: 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",
});
main
branch.fix
, feat
and chore
are recognised by the Release Please bot.<type>[optional scope]: <description>
.Notes: ...
section to provide additional context on why the PR is being merged when it doesn't seem like it should.npm
if there is a version bump.AppImage
installerNSIS
installerDMG
installeryargs
to commander
fs.PathLike
instead of string
..desktop
entry file logic to create-desktop-shortcuts
packageMIT License.