From 6527ee03dc43128bc8b2e649ef87935a87f5ace5 Mon Sep 17 00:00:00 2001 From: younglei Date: Tue, 28 Jun 2022 22:04:05 +0800 Subject: [PATCH 1/3] refactor: index.ts instead of splash.ts --- electron/main/index.ts | 6 +++--- electron/preload/{splash.ts => index.ts} | 0 vite.config.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename electron/preload/{splash.ts => index.ts} (100%) diff --git a/electron/main/index.ts b/electron/main/index.ts index 76cf34d..e130720 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -16,7 +16,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true' let win: BrowserWindow | null = null // Here, you can also use other preload -const splash = join(__dirname, '../preload/splash.js') +const index = join(__dirname, '../preload/index.js') // 🚧 Use ['ENV_NAME'] avoid vite:define plugin const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}` @@ -24,7 +24,7 @@ async function createWindow() { win = new BrowserWindow({ title: 'Main window', webPreferences: { - preload: splash, + preload: index, nodeIntegration: true, contextIsolation: false, }, @@ -77,7 +77,7 @@ app.on('activate', () => { ipcMain.handle("open-win", (event, arg) => { const childWindow = new BrowserWindow({ webPreferences: { - preload: splash, + preload: index, }, }) diff --git a/electron/preload/splash.ts b/electron/preload/index.ts similarity index 100% rename from electron/preload/splash.ts rename to electron/preload/index.ts diff --git a/vite.config.ts b/vite.config.ts index be4c762..d566654 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -23,7 +23,7 @@ export default defineConfig({ preload: { input: { // You can configure multiple preload here - splash: join(__dirname, 'electron/preload/splash.ts'), + index: join(__dirname, 'electron/preload/index.ts'), }, vite: { build: { From 54b44eb4b69251eb337527bf1ec4193c89dd4e36 Mon Sep 17 00:00:00 2001 From: younglei Date: Tue, 28 Jun 2022 22:06:00 +0800 Subject: [PATCH 2/3] chore: docs --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dfc812..e40cf2a 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ npm create electron-vite + │ ├─┬ main + │ │ └── index.ts entry of Electron-main + │ └─┬ preload -+ │ └── splash.ts entry of Electron-preload ++ │ └── index.ts entry of Electron-preload ├─┬ src │ └── main.ts entry of Electron-renderer ├── index.html From f094cbac34205e199a34d64cb150e62af6172176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Wed, 29 Jun 2022 07:33:37 +0800 Subject: [PATCH 3/3] chore: rename --- electron/main/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/electron/main/index.ts b/electron/main/index.ts index e130720..5df8c29 100644 --- a/electron/main/index.ts +++ b/electron/main/index.ts @@ -16,7 +16,7 @@ process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true' let win: BrowserWindow | null = null // Here, you can also use other preload -const index = join(__dirname, '../preload/index.js') +const preload = join(__dirname, '../preload/index.js') // 🚧 Use ['ENV_NAME'] avoid vite:define plugin const url = `http://${process.env['VITE_DEV_SERVER_HOST']}:${process.env['VITE_DEV_SERVER_PORT']}` @@ -24,7 +24,7 @@ async function createWindow() { win = new BrowserWindow({ title: 'Main window', webPreferences: { - preload: index, + preload, nodeIntegration: true, contextIsolation: false, }, @@ -77,7 +77,7 @@ app.on('activate', () => { ipcMain.handle("open-win", (event, arg) => { const childWindow = new BrowserWindow({ webPreferences: { - preload: index, + preload, }, })