npm package: @goauthentik/esbuild-plugin-live-reload
Description: ESBuild + browser refresh. Build completes, page reloads.
Latest version: 2.0.1

**ESBuild Plugin Live Reload**

---

_An ESBuild development plugin that watches for file changes and triggers automatic browser refreshes._

## Quick start

```sh
npm install -D @goauthentik/esbuild-plugin-live-reload
# Or with Yarn:
yarn add -D @goauthentik/esbuild-plugin-live-reload
```

### 1. Configure ESBuild

```js
import { liveReloadPlugin } from "@goauthentik/esbuild-plugin-live-reload";

import esbuild from "esbuild";

const NodeEnvironment = process.env.NODE_ENV || "development";

/**
 * @type {esbuild.BuildOptions}
 */
const buildOptions = {
    // ... Your build options.
    define: {
        "process.env.NODE_ENV": JSON.stringify(NodeEnvironment),
    },
    plugins: [
        /** @see {@link LiveReloadPluginOptions} */
        liveReloadPlugin(),
    ],
};

const buildContext = await esbuild.context(buildOptions);

await buildContext.rebuild();
await buildContext.watch();
```

### 2. Connect your browser

Add the following import near the beginning of your application's entry point.

```js
if (process.env.NODE_ENV === "development") {
    await import("@goauthentik/esbuild-plugin-live-reload");
}
```

That's it! Your browser will now automatically refresh whenever ESBuild finishes rebuilding your code.

## About authentik

[authentik](https://goauthentik.io) is an open source Identity Provider that unifies your identity needs into a single platform, replacing Okta, Active Directory, and Auth0.

We built this plugin to streamline our development workflow, and we're sharing it with the community. If you have any questions, feature requests, or bug reports, please [open an issue](https://github.com/goauthentik/authentik/issues/new/choose).

## License

This code is licensed under the [MIT License](https://www.tldrlegal.com/license/mit-license)

## Plugin API

### EventServerInit

#### Properties

| Property                                      | Type          |
| --------------------------------------------- | ------------- |
| <a id="property-dispatcher"></a> `dispatcher` | `EventTarget` |
| <a id="property-logger"></a> `logger?`        | `Logger`      |
| <a id="property-pathname"></a> `pathname`     | `string`      |

---

### LiveReloadPluginOptions

#### Properties

| Property                                             | Type                                                                                                                                   | Description                                                                                                     |
| ---------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| <a id="property-listenoptions"></a> `listenOptions?` | `ListenOptions`                                                                                                                        | Options for the server's listen method.                                                                         |
| <a id="property-logger-1"></a> `logger?`             | `Logger`                                                                                                                               | A console-like logger.                                                                                          |
| <a id="property-publicurl"></a> `publicURL?`         | `string` \| `URL`                                                                                                                      | A URL to listen on. If not provided, a random port will be used.                                                |
| <a id="property-relativeroot"></a> `relativeRoot?`   | `string`                                                                                                                               | A relative path to the root of the project. This is used to resolve build errors, line numbers, and file paths. |
| <a id="property-server"></a> `server?`               | `Server`\<_typeof_ `IncomingMessage`, _typeof_ `ServerResponse`\> \| `Server`\<_typeof_ `IncomingMessage`, _typeof_ `ServerResponse`\> | A server to listen on. If not provided, a new server will be created.                                           |

---

### RequestHandler

> **RequestHandler** = (`req`, `res`) => `void`

#### Type Parameters

| Type Parameter |
| -------------- |

#### Parameters

| Parameter | Type                   |
| --------- | ---------------------- |
| `req`     | `http.IncomingMessage` |
| `res`     | `http.ServerResponse`  |

#### Returns

`void`

---

### liveReloadPlugin()

> **liveReloadPlugin**(`options?`): `Plugin`

Creates a plugin that listens for build events and sends them to a server-sent event stream.

#### Parameters

| Parameter  | Type                                                  | Description |
| ---------- | ----------------------------------------------------- | ----------- |
| `options?` | [`LiveReloadPluginOptions`](#livereloadpluginoptions) | -           |

#### Returns

`Plugin`

---

### default

Renames and re-exports [liveReloadPlugin](#livereloadplugin)

## Server API

### createRequestHandler()

> **createRequestHandler**(`options`): [`RequestHandler`](#requesthandler)

Create an event request handler.

#### Parameters

| Parameter | Type                                  | Description |
| --------- | ------------------------------------- | ----------- |
| `options` | [`EventServerInit`](#eventserverinit) | -           |

#### Returns

[`RequestHandler`](#requesthandler)

#### Runtime

node