1
1
import { rmSync } from 'fs'
2
2
import { defineConfig } from 'vite'
3
3
import vue from '@vitejs/plugin-vue'
4
- import electron from 'vite-electron-plugin'
5
- import { customStart , loadViteEnv } from 'vite-electron-plugin/plugin'
4
+ import electron from 'vite-plugin-electron'
6
5
import renderer from 'vite-plugin-electron-renderer'
7
6
import pkg from './package.json'
8
7
9
8
rmSync ( 'dist-electron' , { recursive : true , force : true } )
9
+ const sourcemap = ! ! process . env . VSCODE_DEBUG
10
+ const isBuild = process . argv . slice ( 2 ) . includes ( 'build' )
10
11
11
12
// https://vitejs.dev/config/
12
13
export default defineConfig ( {
13
14
plugins : [
14
15
vue ( ) ,
15
- electron ( {
16
- include : [ 'electron' ] ,
17
- transformOptions : {
18
- sourcemap : ! ! process . env . VSCODE_DEBUG ,
16
+ electron ( [
17
+ {
18
+ // Main-Process entry file of the Electron App.
19
+ entry : 'electron/main/index.ts' ,
20
+ onstart ( options ) {
21
+ if ( process . env . VSCODE_DEBUG ) {
22
+ console . log ( /* For `.vscode/.debug.script.mjs` */ '[startup] Electron App' )
23
+ } else {
24
+ options . startup ( )
25
+ }
26
+ } ,
27
+ vite : {
28
+ build : {
29
+ sourcemap,
30
+ minify : isBuild ,
31
+ outDir : 'dist-electron/main' ,
32
+ rollupOptions : {
33
+ external : Object . keys ( pkg . dependencies ) ,
34
+ } ,
35
+ } ,
36
+ } ,
19
37
} ,
20
- plugins : [
21
- ...( process . env . VSCODE_DEBUG
22
- ? [
23
- // Will start Electron via VSCode Debug
24
- customStart ( debounce ( ( ) => console . log ( /* For `.vscode/.debug.script.mjs` */ '[startup] Electron App' ) ) ) ,
25
- ]
26
- : [ ] ) ,
27
- // Allow use `import.meta.env.VITE_SOME_KEY` in Electron-Main
28
- loadViteEnv ( ) ,
29
- ] ,
30
- } ) ,
38
+ {
39
+ entry : 'electron/preload/index.ts' ,
40
+ onstart ( options ) {
41
+ // Notify the Renderer-Process to reload the page when the Preload-Scripts build is complete,
42
+ // instead of restarting the entire Electron App.
43
+ options . reload ( )
44
+ } ,
45
+ vite : {
46
+ build : {
47
+ sourcemap,
48
+ minify : isBuild ,
49
+ outDir : 'dist-electron/preload' ,
50
+ rollupOptions : {
51
+ external : Object . keys ( pkg . dependencies ) ,
52
+ } ,
53
+ } ,
54
+ } ,
55
+ }
56
+ ] ) ,
31
57
// Use Node.js API in the Renderer-process
32
58
renderer ( {
33
59
nodeIntegration : true ,
@@ -51,11 +77,3 @@ export default defineConfig({
51
77
assetsDir : '' , // #287
52
78
} ,
53
79
} )
54
-
55
- function debounce < Fn extends ( ...args : any [ ] ) => void > ( fn : Fn , delay = 299 ) {
56
- let t : NodeJS . Timeout
57
- return ( ( ...args ) => {
58
- clearTimeout ( t )
59
- t = setTimeout ( ( ) => fn ( ...args ) , delay )
60
- } ) as Fn
61
- }
0 commit comments