@@ -2,16 +2,17 @@ import { rmSync } from 'node:fs'
2
2
import path from 'node:path'
3
3
import { defineConfig } from 'vite'
4
4
import react from '@vitejs/plugin-react'
5
- import electron from 'vite-electron-plugin'
6
- import { customStart , loadViteEnv } from 'vite-electron-plugin/plugin'
5
+ import electron from 'vite-plugin-electron'
7
6
import renderer from 'vite-plugin-electron-renderer'
8
7
import pkg from './package.json'
9
8
10
9
// https://vitejs.dev/config/
11
10
export default defineConfig ( ( { command } ) => {
12
11
rmSync ( 'dist-electron' , { recursive : true , force : true } )
13
12
14
- const sourcemap = command === 'serve' || ! ! process . env . VSCODE_DEBUG
13
+ const isServe = command === 'serve'
14
+ const isBuild = command === 'build'
15
+ const sourcemap = isServe || ! ! process . env . VSCODE_DEBUG
15
16
16
17
return {
17
18
resolve : {
@@ -21,34 +22,57 @@ export default defineConfig(({ command }) => {
21
22
} ,
22
23
plugins : [
23
24
react ( ) ,
24
- electron ( {
25
- include : [
26
- 'electron'
27
- ] ,
28
- transformOptions : {
29
- sourcemap,
25
+ electron ( [
26
+ {
27
+ // Main-Process entry file of the Electron App.
28
+ entry : 'electron/main/index.ts' ,
29
+ onstart ( options ) {
30
+ if ( process . env . VSCODE_DEBUG ) {
31
+ console . log ( /* For `.vscode/.debug.script.mjs` */ '[startup] Electron App' )
32
+ } else {
33
+ options . startup ( )
34
+ }
35
+ } ,
36
+ vite : {
37
+ build : {
38
+ sourcemap,
39
+ minify : isBuild ,
40
+ outDir : 'dist-electron/main' ,
41
+ rollupOptions : {
42
+ external : Object . keys ( 'dependencies' in pkg ? pkg . dependencies : { } ) ,
43
+ } ,
44
+ } ,
45
+ } ,
30
46
} ,
31
- plugins : [
32
- ...( ! ! process . env . VSCODE_DEBUG
33
- ? [
34
- // Will start Electron via VSCode Debug
35
- customStart ( ( ) => console . log ( /* For `.vscode/.debug.script.mjs` */ '[startup] Electron App' ) ) ,
36
- ]
37
- : [ ] ) ,
38
- // Allow use `import.meta.env.VITE_SOME_KEY` in Electron-Main
39
- loadViteEnv ( ) ,
40
- ] ,
41
- } ) ,
47
+ {
48
+ entry : 'electron/preload/index.ts' ,
49
+ onstart ( options ) {
50
+ // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
51
+ // instead of restarting the entire Electron App.
52
+ options . reload ( )
53
+ } ,
54
+ vite : {
55
+ build : {
56
+ sourcemap : sourcemap ? 'inline' : undefined , // #332
57
+ minify : isBuild ,
58
+ outDir : 'dist-electron/preload' ,
59
+ rollupOptions : {
60
+ external : Object . keys ( 'dependencies' in pkg ? pkg . dependencies : { } ) ,
61
+ } ,
62
+ } ,
63
+ } ,
64
+ }
65
+ ] ) ,
42
66
// Use Node.js API in the Renderer-process
43
67
renderer ( ) ,
44
68
] ,
45
- server : ! ! process . env . VSCODE_DEBUG ? ( ( ) => {
69
+ server : process . env . VSCODE_DEBUG && ( ( ) => {
46
70
const url = new URL ( pkg . debug . env . VITE_DEV_SERVER_URL )
47
71
return {
48
72
host : url . hostname ,
49
73
port : + url . port ,
50
74
}
51
- } ) ( ) : undefined ,
75
+ } ) ( ) ,
52
76
clearScreen : false ,
53
77
}
54
78
} )
0 commit comments