11import { rmSync } from 'fs'
22import { defineConfig } from 'vite'
33import 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'
65import renderer from 'vite-plugin-electron-renderer'
76import pkg from './package.json'
87
98rmSync ( 'dist-electron' , { recursive : true , force : true } )
9+ const sourcemap = ! ! process . env . VSCODE_DEBUG
10+ const isBuild = process . argv . slice ( 2 ) . includes ( 'build' )
1011
1112// https://vitejs.dev/config/
1213export default defineConfig ( {
1314 plugins : [
1415 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+ } ,
1937 } ,
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+ ] ) ,
3157 // Use Node.js API in the Renderer-process
3258 renderer ( {
3359 nodeIntegration : true ,
@@ -51,11 +77,3 @@ export default defineConfig({
5177 assetsDir : '' , // #287
5278 } ,
5379} )
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