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/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", 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 b3b388b..b9c7317 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -10,13 +10,16 @@ import path from 'node:path' // │ │ ├── main.js // │ │ └── 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.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 -// 🚧 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({ @@ -35,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')) } } 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", 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 =>