vite-plugin-electron-x
A Vite plugin for bundling main.ts
, preload.ts
and running Electron in development.
Usage
Add the plugin in vite.config.js
like this:
export default defineConfig({
plugins: [
electronX({
main: {
// this will output ./build/electron/main.js
entry: './src/electron/main.ts',
outDir: './build/electron',
},
preload: {
// this will output ./build/electro/preload.js
entry: './src/electron/preload.ts',
outDir: './build/electron',
},
}),
]
})
You can load the dev server in Electron using process.env.VITE_DEV_SERVER_URL
:
if (process.env.VITE_DEV_SERVER_URL) {
win.loadURL(`http://localhost:${process.env.VITE_DEV_SERVER_URL}`)
} else {
// win.loadURL('your-production-output.html')
}
API
Docs: https://paka.dev/npm/vite-plugin-electron-x
Dev instructions
Get started
- Install Node.js
- Run
npm install
Commands
-
npm run dev
: Build and watch -
npm run build
: Build -
npm run format
: Format
Publish new version
- Update
CHANGELOG.md
- Check for errors
npm run lint
- Bump the version number
npm version --no-git-tag <version>
- Build the package
npm run build
- Publish the package
npm publish
- Commit with a tag in format "v#.#.#"
- Create GitHub release with release notes