Skip to content

Commit

Permalink
Merge pull request #38 from electron-vite/v0.6.0
Browse files Browse the repository at this point in the history
V0.6.0
  • Loading branch information
caoxiemeihao authored Apr 18, 2024
2 parents e4da734 + 3b0cf29 commit 915cf6b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 1 addition & 3 deletions electron/electron-builder.json5
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion electron/electron-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ declare namespace NodeJS {
* │
* ```
*/
DIST: string
APP_ROOT: string
/** /dist/ or /public/ */
VITE_PUBLIC: string
}
Expand Down
13 changes: 8 additions & 5 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 - [email protected]
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 - [email protected]
const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']

function createWindow() {
win = new BrowserWindow({
Expand All @@ -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'))
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down

0 comments on commit 915cf6b

Please sign in to comment.