Im not new to Electron and i have a good main.js available. But now i want to try dev with electron-vite-react + Typescript. So good so far i dont have any issue with vite for my react frontend.
But now i want convert my all electron main.js to the “index.ts” needed by electron-vite and here come the problems, in my main.js electron serve the file needed in BrowserWindow with classic:
updateWindow.loadFile("update.html");
But if i do this in my index.ts (simplified code):
const updateIsAvailable: boolean = true
if (is.dev && process.env['ELECTRON_RENDERER_URL']) {
if (updateIsAvailable) {
mainWindow.loadURL(`${process.env['ELECTRON_RENDERER_URL']}/udpate.html`)
} else {
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL'])
}
} else {
if (updateIsAvailable) {
mainWindow.loadFile(join(__dirname, '../renderer/update.html'))
} else {
mainWindow.loadFile(join(__dirname, '../renderer/index.html'))
}
}
It dosnt work at all because vite want to reach “update.html” file from the ./out/renderer/ directory . But where can i see what Vite put inside this out/ directory ? The electron.vite.config.ts is like this:
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src')
}
},
plugins: [react()]
}
})
import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
resolve: {
alias: {
'@renderer': resolve('src/renderer/src')
}
},
plugins: [react()]
}
})
I read on internet that i have to add “build – rollupOption” but im not allowed to call “build” in the config file. see here:
https://github.com/electron-vite/electron-vite-react/issues/37#issuecomment-1157074322
Can anyone please explain me how vite handle all the file needed inside my index.ts (my main electron process) please ? I want to learn and improve so any doc are welcom . Thank you very much for your help
I try to add a build option inside my electron.vite.config.ts but i have error message :
No overload corresponds to this call.
The last overload generated the following error.
An object literal can only specify known properties, and 'build' does not exist in the 'ElectronViteConfigExport' type.
What i want is basicly be able to use other html file in special BrowserWindow like “offline.html” and “update.html” and i cant but them inside the “mainWindow” because this special window like update are very small (300×400)