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
|
|
@ -5,7 +5,8 @@
|
|||
"scripts": {
|
||||
"dev:render": "vite --mode renderer",
|
||||
"dev:build": "vite build --mode renderer",
|
||||
"dev:electron": "electron src/main/main.ts"
|
||||
"dev:electron": "NODE_NO_WARNINGS=1 electron src/main/main.ts",
|
||||
"dev": "NODE_NO_WARNINGS=1 npm run dev:render & npm run dev:electron"
|
||||
},
|
||||
"dependencies": {
|
||||
"react": "^19.3.1",
|
||||
|
|
|
|||
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ export default defineConfig(({ mode }) => {
|
|||
if (mode === "renderer") {
|
||||
return {
|
||||
root: path.join(rootDirectory, "/src/renderer"),
|
||||
base: "/",
|
||||
base: path.join(rootDirectory, "/release/app/dist/renderer"),
|
||||
input: "index.html",
|
||||
plugins: [react()],
|
||||
resolve: {
|
||||
// NOTE: Very important to set tsconfigPaths = true
|
||||
|
|
@ -19,8 +20,8 @@ export default defineConfig(({ mode }) => {
|
|||
outDir: path.join(rootDirectory, "/release/app/dist/renderer"),
|
||||
emptyOutDir: true,
|
||||
rolldownOptions: {
|
||||
input: path.join(rootDirectory, "/src/renderer/index.html"),
|
||||
//output: { entryFileNames: "release/app/dist/renderer/renderer.js" }
|
||||
cwd: path.join(rootDirectory, "/src/renderer/"),
|
||||
output: { entryFileNames: "renderer.js" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue