|
| 1 | +# Getting Started |
| 2 | + |
| 3 | +## Installation |
| 4 | + |
| 5 | +Download and install `nw-builder` using your preferred node package manager: |
| 6 | + |
| 7 | +Via `npm` |
| 8 | + |
| 9 | +```shell |
| 10 | +npm install nw-builder |
| 11 | +``` |
| 12 | + |
| 13 | +Via `yarn` |
| 14 | + |
| 15 | +```shell |
| 16 | +yarn add nw-builder |
| 17 | +``` |
| 18 | + |
| 19 | +Via `pnpm` |
| 20 | + |
| 21 | +```shell |
| 22 | +pnpm add nw-builder |
| 23 | +``` |
| 24 | + |
| 25 | +Run the executable to check if it's working correctly: |
| 26 | + |
| 27 | +```shell |
| 28 | +./node_modules/bin/nwbuild.cjs |
| 29 | +``` |
| 30 | + |
| 31 | +This should give an error: |
| 32 | + |
| 33 | +```shell |
| 34 | +[ ERROR ] package.json not found |
| 35 | +``` |
| 36 | + |
| 37 | +## Write your first application: |
| 38 | + |
| 39 | +To learn how to write your NW.js application, follow the steps given [here](https://ayushmxn.github.io/nw-repro/getting-started#write-your-first-nwjs-application). |
| 40 | + |
| 41 | +## Run your first application |
| 42 | + |
| 43 | +CLI usage: |
| 44 | + |
| 45 | +```shell |
| 46 | +./node_modules/bin/nwbuild.cjs ./path/to/nw/app |
| 47 | +``` |
| 48 | + |
| 49 | +Module usage: |
| 50 | + |
| 51 | +```javascript |
| 52 | +const { nwbuild } = require("nw-builder"); |
| 53 | + |
| 54 | +nwbuild({ |
| 55 | + files: "./path/to/nw/app" |
| 56 | +}) |
| 57 | + .then(() => { ... }) |
| 58 | + .catch(() => { ... }) |
| 59 | + .finally(() => { ... }) |
| 60 | +``` |
| 61 | + |
| 62 | +This is the minimum arguments required to run a NW.js application. It detects your current platform, downloads the required NW binary and runs it. |
| 63 | + |
| 64 | +## Build your first application |
| 65 | + |
| 66 | +CLI usage: |
| 67 | + |
| 68 | +```shell |
| 69 | +./node_modules/bin/nwbuild.cjs ./path/to/nw/app --mode=build |
| 70 | +``` |
| 71 | + |
| 72 | +Module usage: |
| 73 | + |
| 74 | +```javascript |
| 75 | +const { nwbuild } = require("nw-builder"); |
| 76 | + |
| 77 | +nwbuild({ |
| 78 | + files: "./path/to/nw/app/dir/**/*.*" |
| 79 | + mode: "build" |
| 80 | +}) |
| 81 | + .then(() => { ... }) |
| 82 | + .catch(() => { ... }) |
| 83 | + .finally(() => { ... }) |
| 84 | +``` |
| 85 | + |
| 86 | +This is the minimum arguments required to build a NW.js application. It detects your current platform, downloads the required NW binary and builds for the current platform. |
| 87 | + |
| 88 | +You can learn more about the configuration options in the [API reference](./api). |
| 89 | + |
| 90 | +## Tips |
| 91 | + |
| 92 | +You may run or build your app repeatedly and will probably want to automate it. You can add a script in your `package.json`: |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "scripts": { |
| 97 | + "run": "nwbuild ./src/**/*", |
| 98 | + "build": "nwbuild ./src/**/* --mode=build" |
| 99 | + } |
| 100 | +} |
| 101 | +``` |
| 102 | + |
| 103 | +However this may not make sense if you have multiple scripts with multiple options potentially leading to a lot of errors and debugging. You can write your run/build script in a module: |
| 104 | + |
| 105 | +```json |
| 106 | +{ |
| 107 | + "scripts": { |
| 108 | + "run": "node run.js", |
| 109 | + "build": "node build.js" |
| 110 | + } |
| 111 | +} |
| 112 | +``` |
| 113 | + |
| 114 | +You can even define your options in your project's `package.json` under the `nwbuild` property. This is ideal if you only have one NW.js run or build process. Note that the `package.json` options override the CLI and module. |
| 115 | + |
| 116 | +`run.js` |
| 117 | + |
| 118 | +```javascript |
| 119 | +nwbuild({ |
| 120 | + files: "./", |
| 121 | +}); |
| 122 | +``` |
| 123 | + |
| 124 | +`package.json` |
| 125 | + |
| 126 | +```json |
| 127 | +{ |
| 128 | + "scripts": { |
| 129 | + "override:cli": "nwbuild ./", |
| 130 | + "override:module": "node run.js" |
| 131 | + }, |
| 132 | + "nwbuild": { |
| 133 | + "files": "./dist/**/*, |
| 134 | + } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +Since `files` is a required argument, you'll have to define it in the CLI or module even if you plan to override it. |
0 commit comments