---
title: "@farmfe/js-plugin-electron"
locale: "zh"
version: "current"
canonicalUrl: "https://farmfe.org/zh/docs/plugins/official-plugins/js-electron"
publicationStatus: "prerelease"
---

<a id="farmfejs-plugin-electron"></a>
# @farmfe/js-plugin-electron


Support development and build workflows for Electron applications using Farm.


<a id="installation"></a>
## Installation


**npm**

```javascript
npm install @farmfe/js-plugin-electron electron
```


**yarn**

```javascript
yarn add @farmfe/js-plugin-electron electron
```


**pnpm**

```javascript
pnpm add @farmfe/js-plugin-electron electron
```



<a id="usage"></a>
## Usage


Configure the Electron main and optional preload entries in ` farm.config.ts `:


```ts
import { defineConfig } from '@farmfe/core';
import electron from '@farmfe/js-plugin-electron';

export default defineConfig({
  plugins: [
    electron({
      main: {
        input: 'electron/main.ts'
      },
      preload: {
        input: 'electron/preload.ts'
      }
    })
  ]
});
```


During development, the plugin starts the Electron app after the Farm dev server is listening and exposes the renderer URL as ` process.env.FARM_DEV_SERVER_URL `.


<a id="options"></a>
## Options


```ts
import type { UserConfig } from '@farmfe/core';

export interface BuildOptions {
  /**
   * Shortcut of `compilation.input`.
   */
  input: string | Record<string, string>;
  farm?: UserConfig;
}

export interface ElectronPluginOptions {
  main: BuildOptions;
  preload?: BuildOptions;
}
```


<a id="main"></a>
### ` main `


Required build options for the Electron main process entry.


<a id="preload"></a>
### ` preload `


Optional build options for Electron preload scripts. Preload builds default to CommonJS output unless the project package is ESM.


<a id="farm"></a>
### ` farm `


Per-target Farm config merged into the generated build for ` main ` or ` preload `. The plugin sets Electron-specific defaults such as ` external: ['^electron$'] `, ` targetEnv: 'library' `, and ` persistentCache: false `.
