
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
vite-plugin-electron
Advanced tools
Integrate Vite and Electron
English | 简体中文
npm i vite-plugin-electron -D
vite.config.ts
import electron from 'vite-plugin-electron'
export default {
plugins: [
electron({
entry: 'electron/main.ts',
}),
],
}
You can use process.env.VITE_DEV_SERVER_URL
when the vite command is called 'serve'
// electron main.js
const win = new BrowserWindow({
title: 'Main window',
})
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(process.env.VITE_DEV_SERVER_URL)
} else {
// load your file
win.loadFile('yourOutputFile.html');
}
electron(config: Configuration | Configuration[])
export interface Configuration {
/**
* Shortcut of `build.lib.entry`
*/
entry?: import('vite').LibraryOptions['entry']
vite?: import('vite').InlineConfig
/**
* Triggered when Vite is built every time.
*
* If this `onstart` is passed, Electron App will not start automatically.
* However, you can start Electroo App via `startup` function.
*/
onstart?: (
this: import('rollup').PluginContext,
options: {
/** Electron App startup function */
startup: (args?: string[]) => Promise<void>
/** Reload Electron-Renderer */
reload: () => void
},
) => void
}
The plugin is just the encapsulation of the built-in scripts of electron-vite-boilerplate/scripts
Let's use the official template-vanilla-ts created based on create vite
as an example
+ ├─┬ electron
+ │ └── main.ts
├─┬ src
│ ├── main.ts
│ ├── style.css
│ └── vite-env.d.ts
├── .gitignore
├── favicon.svg
├── index.html
├── package.json
├── tsconfig.json
+ └── vite.config.ts
electron
folder will be built into the dist/electron
"type": "module"
is not supported in ElectronIn general, Vite may not correctly build Node.js packages, especially C/C++ native modules, but Vite can load them as external packages. So, put your Node.js package in dependencies
. Unless you know how to properly build them with Vite.
By default, vite-plugin-electron
treats packages in dependencies
as external
modules.
You can see 👉 dependencies vs devDependencies
FAQs
Electron 🔗 Vite
We found that vite-plugin-electron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.