Vite Plugin
Transform and bundle code for your Electron Forge app with Vite.
Last updated
Was this helpful?
Transform and bundle code for your Electron Forge app with Vite.
Last updated
Was this helpful?
This plugin makes it easy to set up standard Vite tooling to compile both your main process code and your renderer process code.
You must provide two Vite configuration files: one for the main process in vite.main.config.js
, and one for the renderer process in vite.renderer.config.js
.
For example, this is the taken from Forge's :
Vite's build config generates a separate entry for the main process and preload script, as well as each renderer process.
Your main
entry in your package.json
file needs to point at ".vite/build/main"
, like so:
If using the Vite template, this should be automatically set up for you.
The dev server will be suffixed with _DEV_SERVER_URL
The static file path will be suffixed with _VITE_NAME
In the case of the main_window
, the global variables will be named MAIN_WINDOW_VITE_DEV_SERVER_URL
and MAIN_WINDOW_VITE_NAME
. An example of how to use them is given below:
Config options will largely follow the same standards as non-Electron Vite projects. You can reference for more examples of how to configure each of your entry point's config files.
If you used the template to create your application, native modules will mostly work out of the box. However, to avoid possible build issues, we recommend instructing Vite to load them as external packages:
In order to use Vite's , all loadURL
paths need to reference the global variables that the Vite plugin will define for you: