> ## Documentation Index
> Fetch the complete documentation index at: https://webview.js.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a Standalone Desktop Executable with WebviewJS

> Use the WebviewJS CLI to package your app as a self-contained binary with Node SEA, Deno compile, or Bun compile. No runtime needed on the target machine.

The WebviewJS CLI's `--build` command packages your application into a single self-contained executable. The target machine does not need Node.js, Deno, or Bun installed — the binary includes your code and the chosen runtime. This makes it straightforward to distribute desktop applications to end users without asking them to install a JavaScript runtime first.

<Note>
  The CLI is available as both the `webview` command and the `webviewjs`
  command. Both are identical — use whichever name is more convenient.
</Note>

***

## Install the CLI

Install the package globally to add the `webview` and `webviewjs` commands to your `PATH`, or use `npx` for one-off builds without a global install.

```bash theme={null}
# Global install
npm install -g @webviewjs/webview

# One-off with npx (no global install needed)
npx webview --build --input src/index.js --name myapp
```

***

## Quick start

Point the CLI at your entry file, give the output binary a name, and let it build.

```bash theme={null}
webview --build --input src/index.js --name myapp
```

The executable is written to `dist/` by default. On Windows a `.exe` extension is added automatically.

***

## Choosing a runtime

Use `--runtime` (short: `-R`) to select the compilation tool. When `--runtime` is omitted, the CLI infers the runtime from its own execution environment: `bun` if run under Bun, `deno` if run under Deno, and `node` otherwise. For most users running via `npm` or `npx`, the default is `node`.

<Tabs>
  <Tab title="Node.js (default)">
    Node.js compiles via the [Single Executable Application (SEA)](https://nodejs.org/api/single-executable-applications.html) workflow.
    The CLI automates every step: generating the blob config, injecting it with `postject`, and re-signing the binary on macOS and Windows.

    ```bash theme={null}
    webview --build --runtime node --input src/index.js --name myapp --output dist
    ```

    No additional tools beyond `node` and `npx` are required. `postject` is downloaded automatically via `npx` during the build.
  </Tab>

  <Tab title="Deno">
    Requires `deno` on your `PATH`. Uses `deno compile` to produce a self-contained binary that bundles the Deno runtime.

    ```bash theme={null}
    webview --build --runtime deno --input src/index.ts --name myapp --output dist
    ```

    The CLI runs:

    ```bash theme={null}
    deno compile --allow-all --no-check --output dist/myapp src/index.ts
    ```

    `--allow-all` grants all Deno permissions. Restrict them in your own build script if needed.
  </Tab>

  <Tab title="Bun">
    Requires `bun` on your `PATH`. Uses `bun build --compile` to produce a portable executable.

    ```bash theme={null}
    webview --build --runtime bun --input src/index.ts --name myapp --output dist
    ```

    The CLI runs:

    ```bash theme={null}
    bun build --compile src/index.ts --outfile dist/myapp
    ```

    On Windows, Bun appends `.exe` automatically if the name does not already include it.
  </Tab>
</Tabs>

***

## All CLI options

| Flag          | Short | Default      | Description                                                         |
| ------------- | ----- | ------------ | ------------------------------------------------------------------- |
| `--build`     | `-b`  | —            | Build the project into a standalone executable                      |
| `--runtime`   | `-R`  | inferred     | Runtime: `node`, `deno`, or `bun` (defaults to the current runtime) |
| `--name`      | `-n`  | `webviewjs`  | Output executable name                                              |
| `--input`     | `-i`  | `./index.js` | Entry file path                                                     |
| `--output`    | `-o`  | `./dist`     | Output directory                                                    |
| `--resources` | `-r`  | —            | JSON asset map file path (Node.js runtime only)                     |
| `--dry-run`   | `-d`  | —            | Print what would be done without executing                          |
| `--help`      | `-h`  | —            | Show help text                                                      |
| `--version`   | `-v`  | —            | Show the CLI version                                                |

<Tip>
  Run `--dry-run` before a real build to preview every command the CLI would
  execute. This is useful for verifying that paths, names, and runtime flags
  are correct before committing to a full compilation.

  ```bash theme={null}
  webview --build --runtime node --input src/main.js --name myapp --dry-run
  ```
</Tip>

***

## Bundling assets (Node.js only)

Node.js SEA supports embedding static assets in the binary via the `--resources` flag. Create a JSON file that maps asset names to file paths on disk.

**`assets.json`**

```json theme={null}
{
  "icon.png":    "./assets/icon.png",
  "config.json": "./config.json"
}
```

Pass the file to the CLI:

```bash theme={null}
webview --build --runtime node --resources assets.json --input src/index.js --name myapp
```

Inside your script, read the embedded assets with the `node:sea` API:

```js theme={null}
const { getAsset } = require('node:sea');

const iconBuffer  = getAsset('icon.png');
const configBytes = getAsset('config.json');
const config      = JSON.parse(Buffer.from(configBytes).toString('utf8'));
```

Asset bundling is only available with the Node.js runtime. Deno and Bun include source files directly in their compilation step.

***

## Platform notes

| Platform | Node SEA                         | Deno compile                  | Bun compile                     |
| -------- | -------------------------------- | ----------------------------- | ------------------------------- |
| Windows  | ✅ `.exe` added automatically     | ✅ `.exe` added automatically  | ✅ `.exe` added automatically    |
| macOS    | ✅ Re-signed with `codesign -s -` | ✅ Ad-hoc signed automatically | ✅ Use `codesign` after building |
| Linux    | ✅                                | ✅                             | ✅                               |

**Cross-compilation:**

* **Deno** and **Bun** support a `--target` flag that you can pass via a custom build script for cross-compilation to a different OS or architecture. The WebviewJS CLI does not forward `--target` for you.
* **Node SEA** does not support cross-compilation. Build on the target operating system.

***

## Related pages

* [Installation](/installation) — system requirements and first-time setup
* [Quick Start](/quickstart) — build and run your first WebviewJS window
