@@ -17,39 +17,50 @@ const { buildMainEnv, buildRendererEnv, buildViteConfig, lldRoot } = require("./
17
17
const startDev = async argv => {
18
18
const electron = new Electron ( "./.webpack/main.bundle.js" ) ;
19
19
20
- const devConfig = {
21
- minify : false ,
22
- watch : {
23
- onRebuild ( error , result ) {
24
- if ( error ) {
25
- console . error ( "Watch build failed:" , error ) ;
20
+ const OnRebuildPlugin = {
21
+ name : "onRebuild" ,
22
+ setup ( build ) {
23
+ build . onEnd ( result => {
24
+ if ( result . errors . length > 0 ) {
25
+ console . log ( `Build ended with ${ result . errors . length } errors.` ) ;
26
+ console . log ( result . errors . map ( error => error . message ) . join ( "\n" ) ) ;
26
27
} else {
27
28
electron . reload ( ) ;
28
29
}
29
- } ,
30
+ } ) ;
30
31
} ,
31
32
} ;
32
33
33
34
const mainConfig = {
34
35
...require ( "./config/main.esbuild" ) ,
35
36
define : buildMainEnv ( "development" , argv ) ,
36
- plugins : [ ...( require ( "./config/main.esbuild" ) . plugins || [ ] ) , NodeExternalsPlugin ] ,
37
- ...devConfig ,
37
+ plugins : [
38
+ ...( require ( "./config/main.esbuild" ) . plugins || [ ] ) ,
39
+ NodeExternalsPlugin ,
40
+ OnRebuildPlugin ,
41
+ ] ,
42
+ minify : false ,
38
43
} ;
39
44
const preloaderConfig = {
40
45
...require ( "./config/preloader.esbuild" ) ,
41
46
define : buildMainEnv ( "development" , argv ) ,
42
- ...devConfig ,
47
+ plugins : [ ...( require ( "./config/preloader.esbuild" ) . plugins || [ ] ) , OnRebuildPlugin ] ,
48
+ minify : false ,
43
49
} ;
44
50
const webviewPreloaderConfig = {
45
51
...require ( "./config/webviewPreloader.esbuild" ) ,
46
52
define : buildMainEnv ( "development" , argv ) ,
47
- ...devConfig ,
53
+ plugins : [ ...( require ( "./config/webviewPreloader.esbuild" ) . plugins || [ ] ) , OnRebuildPlugin ] ,
54
+ minify : false ,
48
55
} ;
49
56
const swapConnectWebviewPreloaderConfig = {
50
57
...require ( "./config/swapConnectWebviewPreloader.esbuild" ) ,
51
58
define : buildMainEnv ( "development" , argv ) ,
52
- ...devConfig ,
59
+ plugins : [
60
+ ...( require ( "./config/swapConnectWebviewPreloader.esbuild" ) . plugins || [ ] ) ,
61
+ OnRebuildPlugin ,
62
+ ] ,
63
+ minify : false ,
53
64
} ;
54
65
55
66
try {
@@ -60,14 +71,16 @@ const startDev = async argv => {
60
71
61
72
const rendererServer = await createServer ( buildViteConfig ( argv ) ) ;
62
73
63
- await Promise . all ( [
64
- esbuild . build ( mainConfig ) ,
65
- esbuild . build ( preloaderConfig ) ,
66
- esbuild . build ( webviewPreloaderConfig ) ,
67
- esbuild . build ( swapConnectWebviewPreloaderConfig ) ,
68
- rendererServer . listen ( ) ,
74
+ const contexts = await Promise . all ( [
75
+ esbuild . context ( mainConfig ) ,
76
+ esbuild . context ( preloaderConfig ) ,
77
+ esbuild . context ( webviewPreloaderConfig ) ,
78
+ esbuild . context ( swapConnectWebviewPreloaderConfig ) ,
69
79
] ) ;
70
80
81
+ await rendererServer . listen ( ) ;
82
+ await Promise . all ( contexts . map ( context => context . watch ( ) ) ) ;
83
+
71
84
rendererServer . printUrls ( ) ;
72
85
electron . start ( ) ;
73
86
} ;
0 commit comments