File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,35 @@ export default defineConfig(async ({ command }) => {
127127})
128128```
129129
130+ Or use the helper function
131+
132+ ``` ts
133+ import { defineElectronConfig } from ' electron-incremental-update/vite'
134+
135+ export default defineElectronConfig ({
136+ main: {
137+ files: [' ./electron/main/index.ts' , ' ./electron/main/worker.ts' ],
138+ // see https://github.com/electron-vite/electron-vite-vue/blob/85ed267c4851bf59f32888d766c0071661d4b94c/vite.config.ts#L22-L28
139+ onstart: debugStartup ,
140+ },
141+ preload: {
142+ files: ' ./electron/preload/index.ts' ,
143+ },
144+ updater: {
145+ // options
146+ },
147+ renderer: {
148+ server: process .env .VSCODE_DEBUG && (() => {
149+ const url = new URL (pkg .debug .env .VITE_DEV_SERVER_URL )
150+ return {
151+ host: url .hostname ,
152+ port: + url .port ,
153+ }
154+ })(),
155+ }
156+ })
157+ ```
158+
130159### Modify package.json
131160
132161``` json
Original file line number Diff line number Diff line change 1+ import type { ElectronWithUpdaterOptions } from './option'
2+ import type { UserConfig , UserConfigFn } from 'vite'
3+
4+ import { electronWithUpdater } from './core'
5+
6+ type MakeOptional < T , K extends keyof T > = Partial < Pick < T , K > > & Omit < T , K >
7+
8+ interface ElectronViteHelperOptions extends MakeOptional < ElectronWithUpdaterOptions , 'isBuild' > {
9+ /**
10+ * Config for renderer process
11+ */
12+ renderer ?: UserConfig
13+ }
14+
15+ export function defineElectronConfig (
16+ options : ElectronViteHelperOptions ,
17+ ) : UserConfigFn {
18+ return ( { command } ) => {
19+ options . isBuild ??= command === 'build'
20+ const electronPlugin = electronWithUpdater ( options as ElectronWithUpdaterOptions )
21+ const result = options . renderer ?? { }
22+ result . plugins ??= [ ]
23+ result . plugins . push ( electronPlugin )
24+ return result
25+ }
26+ }
You can’t perform that action at this time.
0 commit comments