Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): add setup to rspack plugin #3451

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/plugin/rspack/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## plugin-rspack

This plugin makes it easy to set up standard webpack tooling to compile both your main process code and your renderer process code, with built-in support for Hot Module Replacement (HMR) in the renderer process and support for multiple renderers.

```javascript
// forge.config.js

module.exports = {
plugins: [
{
name: '@electron-forge/plugin-rspack',
config: {
mainConfig: './rspack.main.config.js',
renderer: {
config: './rspack.renderer.config.js',
entryPoints: [{
name: 'main_window',
html: './src/renderer/index.html',
js: './src/renderer/index.js',
preload: {
js: './src/preload.js'
}
}]
}
}
}
]
};
```
49 changes: 49 additions & 0 deletions packages/plugin/rspack/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "@electron-forge/plugin-rspack",
"version": "7.2.0",
"description": "Rspack plugin for Electron Forge, lets you use Rspack directly in your tooling",
"repository": "https://github.com/electron/forge",
"author": "noghartt",
"license": "MIT",
"main": "dist/RspackPlugin.js",
"typings": "dist/RspackPlugin.d.ts",
"scripts": {
"test": "xvfb-maybe mocha --config ../../../.mocharc.js test/**/*_spec.ts test/*_spec.ts"
},
"engines": {
"node": ">= 16.4.0"
},
"devDependencies": {
"@electron/packager": "^18.1.2",
"@malept/cross-spawn-promise": "^2.0.0",
"@types/node": "^18.0.3",
"chai": "^4.3.3",
"mocha": "^9.0.1",
"sinon": "^13.0.1",
"which": "^2.0.2",
"xvfb-maybe": "^0.2.1"
},
"dependencies": {
"@electron-forge/core-utils": "7.2.0",
"@electron-forge/plugin-base": "7.2.0",
"@electron-forge/shared-types": "7.2.0",
"@electron-forge/web-multi-logger": "7.2.0",
"@rspack/cli": "0.4.4",
"@rspack/core": "0.4.4",
"@rspack/dev-server": "0.4.4",
"chalk": "^4.0.0",
"debug": "^4.3.1",
"fast-glob": "^3.2.7",
"fs-extra": "^10.0.0",
"html-webpack-plugin": "^5.5.3",
"webpack": "^5.69.1",
"webpack-merge": "^5.7.3"
},
"publishConfig": {
"access": "public"
},
"files": [
"dist",
"src"
]
}
127 changes: 127 additions & 0 deletions packages/plugin/rspack/src/Config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { Configuration as RawRspackConfiguration } from '@rspack/core';
import { Configuration as RspackDevServerConfiguration } from '@rspack/dev-server';

export type RspackConfigurationFactory = (
env: string | Record<string, string | boolean | number> | unknown,
args: Record<string, unknown>
) => RspackConfiguration | Promise<RspackConfiguration>;

export type RspackConfiguration = RawRspackConfiguration | RspackConfigurationFactory;

export interface RspackPreloadEntryPoint {
/**
* Relative or absolute path to the preload JS file.
*/
js: string;
/**
* Additional entries to put in the array of entries for this preload script,
* useful if you need to set up things like error reporting as separate
* entry files into your application.
*/
prefixedEntries?: string[];
/**
* The optional webpack config for your preload process.
* Defaults to the renderer webpack config if blank.
*/
config?: RspackConfiguration | string;
}

export interface RspackPluginEntryPointBase {
/**
* Human friendly name of your entry point
*/
name: string;
/**
* Additional entries to put in the array of entries for this entry point,
* useful if you need to set up things like error reporting as separate
* entry files into your application.
*/
prefixedEntries?: string[];
/**
* Additional chunks to include in the outputted HTML file. Use this if you
* set up some custom chunking (e.g. using SplitChunksPlugin).
*/
additionalChunks?: string[];
/**
* Override the webpack config for this renderer based on whether `nodeIntegration` for
* the `BrowserWindow` is enabled. For webpack's `target` option:
*
* * When `nodeIntegration` is true, the `target` is `electron-renderer`.
* * When `nodeIntegration` is false, the `target` is `web`.
*
* Unfortunately, we cannot derive the value from the main process code as it can be
* dynamically generated at run-time, and webpack processes at build-time.
*
* Defaults to `false` (as it is disabled by default in Electron \>= 5) or the value set
* for all entries.
*/
nodeIntegration?: boolean;
}

export interface RspackPluginEntryPointLocalWindow extends RspackPluginEntryPointBase {
/**
* Relative or absolute path to the HTML template file for this entry point.
*/
html: string;
/**
* Relative or absolute path to the main JS file for this entry point.
*/
js: string;
/**
* Information about the preload script for this entry point. If you don't use
* preload scripts, you don't need to set this.
*/
preload?: RspackPreloadEntryPoint;
}

export interface RspackPluginEntryPointPreloadOnly extends RspackPluginEntryPointBase {
/**
* Information about the preload script for this entry point.
*/
preload: RspackPluginEntryPoint;
}

export interface RspackPluginEntryPointNoWindow extends RspackPluginEntryPointBase {
/**
* Relative or absolute path to the main JS file for this entry point.
*/
js: string;
}

export type RspackPluginEntryPoint = RspackPluginEntryPointLocalWindow | RspackPluginEntryPointNoWindow | RspackPluginEntryPointPreloadOnly;

export interface RspackPluginConfig {
/**
* The webpack config for your main process
*/
mainConfig: RspackConfiguration | string;
renderer: RspackPluginRendererConfig | RspackPluginRendererConfig[];
/**
* The TCP port for the dev servers.
* @defaultValue 3000
*/
port?: number;
/**
* The TCP port for web-multi-logger.
* @defaultValue 9000
*/
loggerPort?: number;
devContentSecurityPolicy?: string;
devServer?: Omit<RspackDevServerConfiguration, 'port' | 'static' | 'setupExitSignals' | 'Content-Security-Policy'>;
jsonStats?: boolean;
packageSourceMaps?: boolean;
}

export interface RspackPluginRendererConfig {
/**
* The rspack config for your renderer process
*/
config: RspackConfiguration | string;
jsonStats?: boolean;
nodeIntegration?: boolean;
entryPoints: RspackPluginEntryPoint[];
}

export interface EntryPointPluginConfig {
name: string;
}
Loading