From e636b5d457a94d260acabe6ac8cc618ee2105b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Mon, 15 Apr 2024 10:48:13 +0800 Subject: [PATCH 1/5] chore: correct `process.env.VITE_PUBLIC` --- electron/main.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index b3b388b..1a6bc7d 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -1,6 +1,9 @@ import { app, BrowserWindow } from 'electron' import path from 'node:path' +// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x +const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] + // The built directory structure // // ├─┬─┬ dist @@ -11,12 +14,11 @@ import path from 'node:path' // │ │ └── preload.js // │ process.env.DIST = path.join(__dirname, '../dist') -process.env.VITE_PUBLIC = app.isPackaged ? process.env.DIST : path.join(process.env.DIST, '../public') - +process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL + ? path.join(process.env.DIST, '../public') + : process.env.DIST let win: BrowserWindow | null -// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x -const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] function createWindow() { win = new BrowserWindow({ From 59d3d33655198c376f5d3c9e5999c0871a953251 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Mon, 15 Apr 2024 10:56:36 +0800 Subject: [PATCH 2/5] refactor: better `process.env` assign --- electron/electron-env.d.ts | 2 +- electron/main.ts | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts index bf0cd46..f3b4f4a 100644 --- a/electron/electron-env.d.ts +++ b/electron/electron-env.d.ts @@ -15,7 +15,7 @@ declare namespace NodeJS { * │ * ``` */ - DIST: string + APP_ROOT: string /** /dist/ or /public/ */ VITE_PUBLIC: string } diff --git a/electron/main.ts b/electron/main.ts index 1a6bc7d..b9c7317 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -1,9 +1,6 @@ import { app, BrowserWindow } from 'electron' import path from 'node:path' -// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x -const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] - // The built directory structure // // ├─┬─┬ dist @@ -13,10 +10,14 @@ const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] // │ │ ├── main.js // │ │ └── preload.js // │ -process.env.DIST = path.join(__dirname, '../dist') -process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL - ? path.join(process.env.DIST, '../public') - : process.env.DIST +process.env.APP_ROOT = path.join(__dirname, '..') + +// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - Vite@2.x +export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL'] +export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron') +export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist') + +process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, 'public') : RENDERER_DIST let win: BrowserWindow | null @@ -37,7 +38,7 @@ function createWindow() { win.loadURL(VITE_DEV_SERVER_URL) } else { // win.loadFile('dist/index.html') - win.loadFile(path.join(process.env.DIST, 'index.html')) + win.loadFile(path.join(RENDERER_DIST, 'index.html')) } } From b0f59fb3bb32869f6ea91a250b0afba389cde4eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Thu, 18 Apr 2024 10:02:32 +0800 Subject: [PATCH 3/5] chore: update electron-builder.json5 --- electron/electron-builder.json5 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/electron/electron-builder.json5 b/electron/electron-builder.json5 index 3ff2bfe..d8e386b 100644 --- a/electron/electron-builder.json5 +++ b/electron/electron-builder.json5 @@ -1,6 +1,4 @@ -/** - * @see https://www.electron.build/configuration/configuration - */ +// @see - https://www.electron.build/configuration/configuration { "$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json", "appId": "YourAppID", From 28f7b4ae4caa0888e8a889908da62b6705521dc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Thu, 18 Apr 2024 14:40:32 +0800 Subject: [PATCH 4/5] fix: compatible vitest #26 --- src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index edd13c8..b68e6e3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -305,7 +305,10 @@ window.ipcRenderer.on('main-process-message', (_event, message) => { // Ployfill the Electron and Node.js API for Renderer process. // If you want use Node.js in Renderer process, the \`nodeIntegration\` needs to be enabled in the Main process. // See 👉 https://github.com/electron-vite/vite-plugin-electron-renderer - renderer: {}, + renderer: process.env.NODE_ENV === 'test' + // https://github.com/electron-vite/vite-plugin-electron-renderer/issues/78#issuecomment-2053600808 + ? undefined + : {}, })` if (framework === 'vue' || framework === 'react') { editFile(path.join(root, 'vite.config.ts'), content => From 3b0cf29d1a23d97e9226ade66a69a48898fa36b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leo=20Wang=28=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7=29?= <308487730@qq.com> Date: Thu, 18 Apr 2024 14:57:15 +0800 Subject: [PATCH 5/5] v0.6.0 --- CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a89937c..5c739a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.6.0 (2024-04-18) + +- 28f7b4a fix: compatible vitest #26 +- b0f59fb (github/v0.6.0) chore: update electron-builder.json5 +- 59d3d33 refactor: better `process.env` assign +- e636b5d chore: correct `process.env.VITE_PUBLIC` + ## 0.5.2 (2024-03-29) - 73fecf2 Merge pull request #33 from badspider7/patch-1 diff --git a/package.json b/package.json index a9ab6c0..9d0c4fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "create-electron-vite", - "version": "0.5.2", + "version": "0.6.0", "type": "module", "description": "Scaffolding Your Electron + Vite Project", "license": "MIT",