feat: electron@28, supports "type": "module"

This commit is contained in:
草鞋没号
2023-12-30 14:14:46 +08:00
parent 7ec78d0366
commit 0d71c4bcd1
6 changed files with 23 additions and 22 deletions

View File

@@ -1,14 +1,18 @@
import { app, BrowserWindow, shell, ipcMain } from 'electron'
import { release } from 'node:os'
import { join } from 'node:path'
import { join, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
// The built directory structure
//
// ├─┬ dist-electron
// │ ├─┬ main
// │ │ └── index.js > Electron-Main
// │ │ └── index.mjs > Electron-Main
// │ └─┬ preload
// │ └── index.js > Preload-Scripts
// │ └── index.mjs > Preload-Scripts
// ├─┬ dist
// │ └── index.html > Electron-Renderer
//
@@ -36,7 +40,7 @@ if (!app.requestSingleInstanceLock()) {
let win: BrowserWindow | null = null
// Here, you can also use other preload
const preload = join(__dirname, '../preload/index.js')
const preload = join(__dirname, '../preload/index.mjs')
const url = process.env.VITE_DEV_SERVER_URL
const indexHtml = join(process.env.DIST, 'index.html')
@@ -47,9 +51,10 @@ async function createWindow() {
webPreferences: {
preload,
// Warning: Enable nodeIntegration and disable contextIsolation is not secure in production
// nodeIntegration: true,
// Consider using contextBridge.exposeInMainWorld
// Read more on https://www.electronjs.org/docs/latest/tutorial/context-isolation
nodeIntegration: true,
contextIsolation: false,
},
})