> ## 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 modules

> Compile and install card modules for production.

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

## Compilation

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

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

This command performs the following build steps:

1. Clears any previous builds by deleting the `module_out/` directory.
2. Compiles your module using Rollup with the config file `module/rollup.config.mjs`.
3. Optimizes and bundles both your backend and frontend code.
4. Outputs the compiled assets into the `module_out/` directory.

### Build output structure

The build process generates compiled scripts inside the `module_out/scripts/` directory:

* `main.mjs` - Contains the compiled backend main-process bundle.
* `renderer.mjs` - Contains the compiled frontend configuration bundle.

***

## Local installation and testing

To test the production build of your module 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 module metadata ID. For example, if your module ID is `offline-container`, create a directory path like:

```
Documents/LynxHub/Plugins/offline-container/
```

### 3. Copy the compiled files

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

1. Copy all compiled files from `module_out/scripts/` directly into the `Plugins/<module-id>/scripts/` folder. Both `main.mjs` and `renderer.mjs` must reside in the root of the `scripts/` directory.
2. Copy your module's static `metadata.json` file to the root of the module folder (`Plugins/<module-id>/metadata.json`).

### 4. Verify directory structure

Ensure your module directory matches the following layout:

```
Documents/LynxHub/Plugins/<module-id>/
├── metadata.json
└── scripts/
    ├── main.mjs
    └── renderer.mjs
```

Restart LynxHub to load and verify the compiled module.

***

## Production builds

When you prepare your module 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:module`.
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 modules](/plugins/modules/publish) guide.
