Clean example that combines svelte vite and electron.
Start with: npm start
Vite builds the renderer and watches for changes. Meanwhile, electron starts up and loads the index.html file built.
Build with npm run build
Vite statically builds the renderer into
src/renderer/dist
, then electron-builder packages up the build into an executable.
Enjoy!
src/index.js
- Electron entrypoint for appsrc/renderer/index.html
- Renderer entrypoint for electronTo redo this repo:
npm init vite@latest
, select svelte.public
, src
, index.html
to src/renderer
. You can remote the fluff like .vscode
.npm install --save-dev electron electron-builder concurrently cross-env
package.json
:"type": "module",
"main": "src/index.js",
"scripts": {
"start": "cross-env NODE_ENV=development concurrently \"npm run web:watch\" \"npm run electron:start\"",
"web:watch": "vite",
"electron:start": "electron src",
"build": "vite build && electron-builder"
}
"build": {
"files": [
"src/**/*"
]
}
src/index.js
. Follow getting started guide in Electron and when creating the window, use something like this:if (process.env.NODE_ENV !== 'development') {
// Load production build
win.loadFile(`${__dirname}/renderer/dist/index.html`)
} else {
// Load vite dev server page
console.log('Development mode')
win.loadURL('http://localhost:3000/')
}