electron-vite-vue/src/main/index.ts

30 lines
687 B
TypeScript
Raw Normal View History

2020-08-16 20:42:52 +08:00
/**
* electron
*/
2021-02-18 16:11:08 +08:00
require('dotenv').config({ path: join(__dirname, '../../.env') })
2020-08-16 20:42:52 +08:00
import { join } from 'path'
import { app, BrowserWindow } from 'electron'
2020-12-24 18:38:33 +08:00
let win: BrowserWindow
2020-08-16 20:42:52 +08:00
function createWin() {
// 创建浏览器窗口
win = new BrowserWindow({
width: 1024,
height: 768,
2020-08-31 09:50:57 +08:00
webPreferences: {
nodeIntegration: true,
2020-12-24 18:38:33 +08:00
preload: join(__dirname, '../preload/index.js'),
2020-08-31 09:50:57 +08:00
},
2020-08-16 20:42:52 +08:00
})
2021-02-17 22:27:40 +08:00
const URL = app.isPackaged
? `file://${join(__dirname, '../render/index.html')}` // vite 构建后的静态文件地址
: `http://localhost:${process.env.PORT}` // vite 启动的服务器地址
2020-08-16 20:42:52 +08:00
2020-12-24 18:38:33 +08:00
win?.loadURL(URL)
2020-08-16 20:42:52 +08:00
}
app.whenReady().then(createWin)