thergbcrow
Nuxt3 Generate - static assets relative path
import { app, BrowserWindow } from 'electron'
import express, { static as serveStatic } from 'express'
import * as path from "node:path";
import { fileURLToPath } from 'url';
import 'dotenv/config'
import titleBar from "./modules/title-bar.js";
const filename = fileURLToPath(import.meta.url);
const public = path.join(path.dirname(filename), '../.output/public')
const createWindow = () => {
return new BrowserWindow({
width: 1440,
height: 1024,
minWidth: 1024,
minHeight: 676,
backgroundColor: '#000',
webPreferences: {
webSecurity: false,
nodeIntegration: true,
contextIsolation: false,
},
titleBarStyle: 'hiddenInset',
})
}
const startServer = (window) => {
if(process.env.NODE_ENV !== 'dev') {
const server = express()
server.use('/', serveStatic(public))
const listener = server.listen(8079, 'localhost', () => {
const port = (listener.address()).port
window.loadURL(
http://localhost:${port}
)
console.log([+] Serving from http://localhost:${port}
)
})
}
window.loadURL(http://localhost:3000
)
console.log([+] Serving from http://localhost:3000}
)
}
app.on('ready', () => {
const browserWindow = createWindow()
startServer(browserWindow)
titleBar(browserWindow)
})
SOLVED5 replies