feat: finally set up electron and vite together for build and live dev.
essentially vite and electron now can work together for live development of an app without dealing with possible dimension issues or any of the works
This commit is contained in:
parent
73cb54ad4f
commit
6c8ea122cd
3 changed files with 29 additions and 8 deletions
|
|
@ -1,9 +1,19 @@
|
|||
import { app, BrowserWindow } from "electron"
|
||||
import { pathToFileURL } from "node:url"
|
||||
import { fileURLToPath, format } from "node:url"
|
||||
import path from "node:path"
|
||||
|
||||
const test = pathToFileURL((path.dirname(".") + "/release/app/dist/renderer/index.html")).href
|
||||
console.log(test)
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
const distRendererPath = path.join(__dirname, "../../release/app/dist/renderer/")
|
||||
//console.log(distRendererPath)
|
||||
|
||||
// Reference: https://www.electronjs.org/docs/latest/api/browser-window
|
||||
const fileURL = format({
|
||||
protocol: "file",
|
||||
slashes: true,
|
||||
pathname: path.join(distRendererPath, "index.html")
|
||||
})
|
||||
|
||||
const mainWindowInit = () => {
|
||||
const window = new BrowserWindow({
|
||||
|
|
@ -11,7 +21,16 @@ const mainWindowInit = () => {
|
|||
height: 720
|
||||
})
|
||||
|
||||
window.loadURL(test)
|
||||
window.loadURL("http://localhost:5173").then(
|
||||
// NOTE: On reject...
|
||||
() => {
|
||||
console.log("Using vite server...")
|
||||
}),
|
||||
// NOTE: On fulfill...
|
||||
() => {
|
||||
console.log("No vite server found!\nUsing dist files...")
|
||||
window.loadURL(fileURL)
|
||||
}
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue