@@ -20,6 +20,10 @@ module.exports = (api, options) => {
20
20
( usesTypescript ? 'src/background.ts' : 'src/background.js' )
21
21
const mainProcessChain =
22
22
pluginOptions . chainWebpackMainProcess || ( config => config )
23
+ const bundleMainProcess =
24
+ pluginOptions . bundleMainProcess == null
25
+ ? true
26
+ : pluginOptions . bundleMainProcess
23
27
24
28
// Apply custom webpack config
25
29
api . chainWebpack ( async config => {
@@ -106,46 +110,59 @@ module.exports = (api, options) => {
106
110
api . resolve ( outputDir + '/bundled/css/fonts' )
107
111
)
108
112
}
109
- // Build the main process into the renderer process output dir
110
- const bundle = bundleMain ( {
111
- mode : 'build' ,
112
- api,
113
- args,
114
- pluginOptions,
115
- outputDir,
116
- mainProcessFile,
117
- mainProcessChain,
118
- usesTypescript
119
- } )
120
- console . log ( 'Bundling main process:\n' )
121
- bundle . run ( ( err , stats ) => {
122
- if ( err ) {
123
- console . error ( err . stack || err )
124
- if ( err . details ) {
125
- console . error ( err . details )
113
+
114
+ if ( bundleMainProcess ) {
115
+ // Build the main process into the renderer process output dir
116
+ const bundle = bundleMain ( {
117
+ mode : 'build' ,
118
+ api,
119
+ args,
120
+ pluginOptions,
121
+ outputDir,
122
+ mainProcessFile,
123
+ mainProcessChain,
124
+ usesTypescript
125
+ } )
126
+ console . log ( 'Bundling main process:\n' )
127
+ bundle . run ( ( err , stats ) => {
128
+ if ( err ) {
129
+ console . error ( err . stack || err )
130
+ if ( err . details ) {
131
+ console . error ( err . details )
132
+ }
133
+ return reject ( err )
126
134
}
127
- return reject ( err )
128
- }
129
135
130
- const info = stats . toJson ( )
136
+ const info = stats . toJson ( )
131
137
132
- if ( stats . hasErrors ( ) ) {
133
- return reject ( info . errors )
134
- }
138
+ if ( stats . hasErrors ( ) ) {
139
+ return reject ( info . errors )
140
+ }
135
141
136
- if ( stats . hasWarnings ( ) ) {
137
- console . warn ( info . warnings )
138
- }
142
+ if ( stats . hasWarnings ( ) ) {
143
+ console . warn ( info . warnings )
144
+ }
145
+
146
+ console . log (
147
+ stats . toString ( {
148
+ chunks : false ,
149
+ colors : true
150
+ } )
151
+ )
139
152
153
+ buildApp ( )
154
+ } )
155
+ } else {
140
156
console . log (
141
- stats . toString ( {
142
- chunks : false ,
143
- colors : true
144
- } )
157
+ 'Not bundling main process as bundleMainProcess was set to false in plugin options'
158
+ )
159
+ // Copy main process file instead of bundling it
160
+ fs . copySync (
161
+ api . resolve ( mainProcessFile ) ,
162
+ api . resolve ( `${ outputDir } /bundled/background.js` )
145
163
)
146
-
147
164
buildApp ( )
148
- } )
165
+ }
149
166
}
150
167
function buildApp ( ) {
151
168
console . log ( '\nBuilding app with electron-builder:\n' )
@@ -210,116 +227,133 @@ module.exports = (api, options) => {
210
227
// Kill old Electron process
211
228
child . kill ( )
212
229
}
213
- // Build the main process
214
- const bundle = bundleMain ( {
215
- mode : 'serve' ,
216
- api,
217
- args,
218
- pluginOptions,
219
- outputDir,
220
- mainProcessFile,
221
- mainProcessChain,
222
- usesTypescript,
223
- server
224
- } )
225
- console . log ( 'Bundling main process:\n' )
226
- bundle . run ( ( err , stats ) => {
227
- if ( err ) {
228
- console . error ( err . stack || err )
229
- if ( err . details ) {
230
- console . error ( err . details )
230
+
231
+ if ( bundleMainProcess ) {
232
+ // Build the main process
233
+ const bundle = bundleMain ( {
234
+ mode : 'serve' ,
235
+ api,
236
+ args,
237
+ pluginOptions,
238
+ outputDir,
239
+ mainProcessFile,
240
+ mainProcessChain,
241
+ usesTypescript,
242
+ server
243
+ } )
244
+ console . log ( 'Bundling main process:\n' )
245
+ bundle . run ( ( err , stats ) => {
246
+ if ( err ) {
247
+ console . error ( err . stack || err )
248
+ if ( err . details ) {
249
+ console . error ( err . details )
250
+ }
251
+ process . exit ( 1 )
231
252
}
232
- process . exit ( 1 )
233
- }
234
253
235
- const info = stats . toJson ( )
254
+ const info = stats . toJson ( )
236
255
237
- if ( stats . hasErrors ( ) ) {
238
- console . error ( info . errors )
239
- process . exit ( 1 )
240
- }
256
+ if ( stats . hasErrors ( ) ) {
257
+ console . error ( info . errors )
258
+ process . exit ( 1 )
259
+ }
241
260
242
- if ( stats . hasWarnings ( ) ) {
243
- console . warn ( info . warnings )
244
- }
261
+ if ( stats . hasWarnings ( ) ) {
262
+ console . warn ( info . warnings )
263
+ }
245
264
246
- console . log (
247
- stats . toString ( {
248
- chunks : false ,
249
- colors : true
250
- } )
251
- )
252
- if ( args . debug ) {
253
- // Do not launch electron and provide instructions on launching through debugger
254
265
console . log (
255
- '\nNot launching electron as debug argument was passed. You must launch electron though your debugger.'
256
- )
257
- console . log (
258
- `If you are using Spectron, make sure to set the IS_TEST env variable to true.`
266
+ stats . toString ( {
267
+ chunks : false ,
268
+ colors : true
269
+ } )
259
270
)
271
+ launchElectron ( )
272
+ } )
273
+ } else {
274
+ console . log (
275
+ 'Not bundling main process as bundleMainProcess was set to false in plugin options'
276
+ )
277
+ // Copy main process file instead of bundling it
278
+ fs . copySync (
279
+ api . resolve ( mainProcessFile ) ,
280
+ api . resolve ( `${ outputDir } /index.js` )
281
+ )
282
+ launchElectron ( )
283
+ }
284
+ }
285
+ // Initial start of Electron
286
+ startElectron ( )
287
+ // Restart on main process file change
288
+ mainProcessWatch . forEach ( file => {
289
+ fs . watchFile ( api . resolve ( file ) , startElectron )
290
+ } )
291
+
292
+ function launchElectron ( ) {
293
+ if ( args . debug ) {
294
+ // Do not launch electron and provide instructions on launching through debugger
295
+ console . log (
296
+ '\nNot launching electron as debug argument was passed. You must launch electron though your debugger.'
297
+ )
298
+ console . log (
299
+ `If you are using Spectron, make sure to set the IS_TEST env variable to true.`
300
+ )
301
+ console . log (
302
+ 'Learn more about debugging the main process at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#debugging.'
303
+ )
304
+ } else if ( args . headless ) {
305
+ // Log information for spectron
306
+ console . log ( `$outputDir=${ outputDir } ` )
307
+ console . log ( `$WEBPACK_DEV_SERVER_URL=${ server . url } ` )
308
+ } else {
309
+ // Launch electron with execa
310
+ if ( mainProcessArgs ) {
260
311
console . log (
261
- 'Learn more about debugging the main process at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/testingAndDebugging.html#debugging.'
312
+ '\nLaunching Electron with arguments: ' +
313
+ mainProcessArgs . join ( ' ' ) +
314
+ ' ...'
262
315
)
263
- } else if ( args . headless ) {
264
- // Log information for spectron
265
- console . log ( `$outputDir=${ outputDir } ` )
266
- console . log ( `$WEBPACK_DEV_SERVER_URL=${ server . url } ` )
267
316
} else {
268
- // Launch electron with execa
269
- if ( mainProcessArgs ) {
270
- console . log (
271
- '\nLaunching Electron with arguments: ' +
272
- mainProcessArgs . join ( ' ' ) +
273
- ' ...'
274
- )
275
- } else {
276
- console . log ( '\nLaunching Electron...' )
277
- }
278
- child = execa (
279
- require ( 'electron' ) ,
280
- [
281
- // Have it load the main process file built with webpack
282
- outputDir ,
283
- // Append other arguments specified in plugin options
284
- ...mainProcessArgs
285
- ] ,
286
- {
287
- cwd : api . resolve ( '.' ) ,
288
- env : {
289
- ...process . env ,
290
- // Disable electron security warnings
291
- ELECTRON_DISABLE_SECURITY_WARNINGS : true
292
- }
317
+ console . log ( '\nLaunching Electron...' )
318
+ }
319
+ child = execa (
320
+ require ( 'electron' ) ,
321
+ [
322
+ // Have it load the main process file built with webpack
323
+ outputDir ,
324
+ // Append other arguments specified in plugin options
325
+ ...mainProcessArgs
326
+ ] ,
327
+ {
328
+ cwd : api . resolve ( '.' ) ,
329
+ env : {
330
+ ...process . env ,
331
+ // Disable electron security warnings
332
+ ELECTRON_DISABLE_SECURITY_WARNINGS : true
293
333
}
294
- )
295
-
296
- if ( pluginOptions . removeElectronJunk === false ) {
297
- // Pipe output to console
298
- child . stdout . pipe ( process . stdout )
299
- child . stderr . pipe ( process . stderr )
300
- } else {
301
- // Remove junk terminal output (#60)
302
- child . stdout
303
- . pipe ( require ( './lib/removeJunk.js' ) ( ) )
304
- . pipe ( process . stdout )
305
- child . stderr
306
- . pipe ( require ( './lib/removeJunk.js' ) ( ) )
307
- . pipe ( process . stderr )
308
334
}
335
+ )
309
336
310
- child . on ( 'exit' , ( ) => {
311
- // Exit when electron is closed
312
- process . exit ( 0 )
313
- } )
337
+ if ( pluginOptions . removeElectronJunk === false ) {
338
+ // Pipe output to console
339
+ child . stdout . pipe ( process . stdout )
340
+ child . stderr . pipe ( process . stderr )
341
+ } else {
342
+ // Remove junk terminal output (#60)
343
+ child . stdout
344
+ . pipe ( require ( './lib/removeJunk.js' ) ( ) )
345
+ . pipe ( process . stdout )
346
+ child . stderr
347
+ . pipe ( require ( './lib/removeJunk.js' ) ( ) )
348
+ . pipe ( process . stderr )
314
349
}
315
- } )
350
+
351
+ child . on ( 'exit' , ( ) => {
352
+ // Exit when electron is closed
353
+ process . exit ( 0 )
354
+ } )
355
+ }
316
356
}
317
- // Initial start of Electron
318
- startElectron ( )
319
- // Restart on main process file change
320
- mainProcessWatch . forEach ( file => {
321
- fs . watchFile ( api . resolve ( file ) , startElectron )
322
- } )
323
357
}
324
358
)
325
359
0 commit comments