# electron-forge-plugin-rspack

> Webpack plugin for Electron Forge

Latest version **1.0.0** (published 2024-09-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install electron-forge-plugin-rspack
pnpm add electron-forge-plugin-rspack
yarn add electron-forge-plugin-rspack
bun add electron-forge-plugin-rspack
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-09-03 |
| First published | 2023-12-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 16.4.0 |
| Dependencies | 10 |
| Unpacked size | 56.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 10 |
| Author | noshower |
| Maintainers | noshower |
| Keywords | electron, forge, plugin, rspack |

## Links

- npm: https://www.npmjs.com/package/electron-forge-plugin-rspack
- Repository: https://github.com/noshower/electron-forge-plugin-rspack
- Homepage: https://github.com/noshower/electron-forge-plugin-rspack#readme
- Issues: https://github.com/noshower/electron-forge-plugin-rspack/issues
- npm.io page: https://npm.io/package/electron-forge-plugin-rspack

## Dependencies (10)

- [debug](https://npm.io/package/debug.md) ^4.3.4
- [fs-extra](https://npm.io/package/fs-extra.md) ^11.2.0
- [@rspack/core](https://npm.io/package/@rspack/core.md) ^1.0.1
- [webpack-merge](https://npm.io/package/webpack-merge.md) ^5.10.0
- [@rspack/dev-server](https://npm.io/package/@rspack/dev-server.md) ^1.0.1
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^5.5.4
- [@electron-forge/core-utils](https://npm.io/package/@electron-forge/core-utils.md) 7.2.0
- [@electron-forge/plugin-base](https://npm.io/package/@electron-forge/plugin-base.md) 7.2.0
- [@electron-forge/shared-types](https://npm.io/package/@electron-forge/shared-types.md) 7.2.0
- [@electron-forge/web-multi-logger](https://npm.io/package/@electron-forge/web-multi-logger.md) 7.2.0

## Recent versions

- 1.0.0 (latest) — 2024-09-03
- 0.0.3 — 2023-12-14
- 0.0.2 — 2023-12-10
- 0.0.1 — 2023-12-10

## README

# electron-forge-plugin-rspack

# Support rspack 1.0

> Transform and bundle code for your Electron Forge app with rspack.

## This project forked from [plugin-webpack](https://github.com/electron/forge/tree/main/packages/plugin/webpack), [document](https://www.electronforge.io/config/plugins/webpack#advanced-configuration)

## It's [electron-forge](https://www.electronforge.io/) plugin.

# Installation

```
npm install --save-dev electron-forge-plugin-rspack
```

# Usage

## Plugin configuration

You must provide two rspack configuration files: one for the main process in **mainConfig**, and one for the renderer process in **renderer.config**.The complete config options are available in the API docs under [WebpackPluginConfig](https://js.electronforge.io/interfaces/_electron_forge_plugin_webpack.WebpackPluginConfig.html)

For example, this is the configuration taken from [electron-forge-rspack-template](https://github.com/noshower/electron-forge-rspack-template):

```javascript
// forge.config.ts

import type { ForgeConfig } from "@electron-forge/shared-types";
import { RspackPlugin } from "electron-forge-plugin-rspack";

import { mainConfig } from "./rspack.main.config";
import { rendererConfig } from "./rspack.renderer.config";

const config: ForgeConfig = {
  // ...
  plugins: [
    new RspackPlugin({
      mainConfig,
      renderer: {
        config: rendererConfig,
        entryPoints: [
          {
            html: "./index.html",
            js: "./src/renderer.ts",
            name: "main_window",
            preload: {
              js: "./src/preload.ts",
            },
          },
        ],
      },
    }),
  ],
  // ...
};

export default config;
```

## Project files

This plugin generates a separate entry for the main process, as well as each renderer process and preload script.

You need to do two things in your project files in order to make this plugin work.

### package.json

First, your main entry in your package.json file needs to point at "./.rspack/main" like so:

```
// package.json
{
  "name": "my-app",
  "main": "./.rspack/main",
  // ...
}
```

### Main process code

Second, all loadURL and preload paths need to reference the magic global variables that this plugin will define for you.

Each entry point has two globals defined based on the name assigned to your entry point:

- The renderer's entry point will be suffixed with **\_RSPACK_ENTRY**

- The renderer's preload script will be suffixed with **\_PRELOAD_RSPACK_ENTRY**

In the case of the **main_window** entry point in the earlier example, the global variables will be named **MAIN_WINDOW_RSPACK_ENTRY** and **MAIN_WINDOW_PRELOAD_RSPACK_ENTRY**. An example of how to use them is given below:

```
const mainWindow = new BrowserWindow({
  webPreferences: {
    preload: MAIN_WINDOW_PRELOAD_RSPACK_ENTRY
  }
});

mainWindow.loadURL(MAIN_WINDOW_RSPACK_ENTRY);
```

These variables are only defined in the main process. If you need to use one of these paths in a renderer (e.g. to pass a preload script to a <webview> tag), you can pass the magic variable value with a synchronous IPC round trip.

```
// main.js
// make sure this listener is set before your renderer.js code is called
ipcMain.on('get-preload-path', (e) => {
  e.returnValue = WINDOW_PRELOAD_WEBPACK_ENTRY;
});


// prelaod.js
const { contextBridge, ipcRenderer } = require('electron');

contextBridge.exposeInMainWorld('electron', {
  getPreloadPath: () => ipcRenderer.sendSync('get-preload-path')
});

// renderer.js
const preloadPath = window.electron.getPreloadPath();
```

### Usage with Typescript

If you're using the rspack plugin with TypeScript, you will need to manually declare these magic variables to avoid compiler errors.

```
// main.ts
declare const MAIN_WINDOW_RSPACK_ENTRY: string;
declare const MAIN_WINDOW_PRELOAD_RSPACK_ENTRY: string;
```

### Other

this plugin uses [@rspack/dev-server](https://www.rspack.dev/config/dev-server.html) to help you quickly iterate on renderer process code in development mode. Running **electron-forge start** with the rspack plugin active will launch a dev server that is configurable through the plugin config.

## Example

```
git clone https://github.com/noshower/electron-forge-rspack-template
cd electron-forge-rspack-template
npm i
npm start
```

---
_Source: https://npm.io/package/electron-forge-plugin-rspack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
