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

# Building extensions

> Compile, bundle, and install extensions for distribution.

You must compile and package your extension to test it in a production environment or prepare it for publication.

## Compilation

To build your extension, run the build script in the LynxHub root directory:

```bash theme={null}
npm run build:extension
```

This command performs the following build steps:

1. Clears any previous builds by deleting the `extension_out/` directory.
2. Compiles your extension using the config file `extension/electron.vite.config.ts`.
3. Optimizes and bundles both your backend and frontend code.
4. Outputs the compiled assets into the `extension_out/` directory.

### Build output structure

The build process generates two main directories inside `extension_out/`:

* `main/` - Contains the compiled backend main-process bundle (`mainEntry.cjs`).
* `renderer/` - Contains the compiled frontend assets, including the remote entry file (`rendererEntry.mjs`).

***

## Local installation and testing

To test the production build of your extension locally, you must copy the compiled files to the LynxHub user plugins folder.

### 1. Locate the plugins directory

The default application data directory is determined by your installation type:

* **Installed**: `C:\Users\<Your-Username>\Documents\LynxHub` (on Windows)
* **Portable**: `./LynxHub_Data` (located in your application executable folder)

Navigate to the `Plugins/` folder inside this directory.

### 2. Create the target folder

Create a new subfolder named after your extension metadata ID. For example, if your extension ID is `custom-actions`, create a directory path like:

```
Documents/LynxHub/Plugins/custom-actions/
```

### 3. Copy the compiled files

Create a `scripts/` folder inside your extension directory. Copy the compiled outputs from `extension_out/` as follows:

1. Copy the file `extension_out/main/mainEntry.cjs` to `Plugins/<extension-id>/scripts/main/mainEntry.cjs`.
2. Copy all files from `extension_out/renderer/` to the folder `Plugins/<extension-id>/scripts/renderer/`.
3. Copy your extension's static `metadata.json` file to the root of the extension folder (`Plugins/<extension-id>/metadata.json`).

### 4. Verify directory structure

Ensure your extension directory matches the following layout:

```
Documents/LynxHub/Plugins/<extension-id>/
├── metadata.json
└── scripts/
    ├── main/
    │   └── mainEntry.cjs
    └── renderer/
        ├── rendererEntry.mjs
        └── [other bundled assets]
```

Restart LynxHub to load and verify the compiled extension.

***

## Production builds

When you prepare your extension for publication, you must push the compiled build assets to the compiled branch (`main`).

1. Commit all raw source files to your `source` branch.
2. Run the compilation command `npm run build:extension`.
3. Switch to your `main` branch.
4. Copy the compiled `scripts/` directory to the root of the `main` branch.
5. Push the compiled branch to your remote repository.

For more details on repository branches, see the [Publishing extensions](/plugins/extensions/publish) guide.
