File tree Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Expand file tree Collapse file tree 3 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -340,6 +340,39 @@ describe('electron:serve', () => {
340
340
expect ( mainConfig . node . shouldBe ) . toBe ( 'expected' )
341
341
} )
342
342
343
+ test ( 'Custom launch arguments is used if provided' , async ( ) => {
344
+ let watchCb
345
+ fs . watchFile . mockImplementation ( ( file , cb ) => {
346
+ // Set callback to be called later
347
+ watchCb = cb
348
+ } )
349
+ await runCommand ( 'electron:serve' , {
350
+ pluginOptions : {
351
+ electronBuilder : {
352
+ mainProcessFile : 'customBackground' ,
353
+ mainProcessArgs : [ '--a-flag' , 'a-value' ]
354
+ }
355
+ }
356
+ } )
357
+
358
+ expect ( execa ) . toHaveBeenCalledTimes ( 1 )
359
+ expect ( execa . mock . calls [ 0 ] [ 1 ] ) . toEqual ( [
360
+ 'dist_electron' ,
361
+ '--a-flag' ,
362
+ 'a-value'
363
+ ] )
364
+
365
+ // Mock change of background file
366
+ watchCb ( )
367
+
368
+ expect ( execa ) . toHaveBeenCalledTimes ( 2 )
369
+ expect ( execa . mock . calls [ 0 ] [ 1 ] ) . toEqual ( [
370
+ 'dist_electron' ,
371
+ '--a-flag' ,
372
+ 'a-value'
373
+ ] )
374
+ } )
375
+
343
376
test ( 'process.env.IS_ELECTRON is set to true' , async ( ) => {
344
377
await runCommand ( 'electron:serve' )
345
378
expect ( process . env . IS_ELECTRON ) . toBe ( 'true' )
Original file line number Diff line number Diff line change @@ -62,7 +62,11 @@ module.exports = {
62
62
mainProcessFile: ' src/myBackgroundFile.js' ,
63
63
// Provide an array of files that, when changed, will recompile the main process and restart Electron
64
64
// Your main process file will be added by default
65
- mainProcessWatch: [' src/myFile1' , ' src/myFile2' ]
65
+ mainProcessWatch: [' src/myFile1' , ' src/myFile2' ],
66
+ // [1.0.0-rc.4+] Provide a list of arguments that Electron will be launched with during "electron:serve",
67
+ // which can be accessed from the main process (src/background.js).
68
+ // Note that it is ignored when --debug flag is used with "electron:serve", as you must launch Electron yourself
69
+ mainProcessArgs: [' --arg-name' , ' arg-value' ]
66
70
}
67
71
}
68
72
}
Original file line number Diff line number Diff line change @@ -187,6 +187,7 @@ module.exports = (api, options) => {
187
187
mainProcessFile ,
188
188
...( pluginOptions . mainProcessWatch || [ ] )
189
189
]
190
+ const mainProcessArgs = pluginOptions . mainProcessArgs || [ ]
190
191
191
192
console . log ( '\nStarting development server:\n' )
192
193
// Run the serve command
@@ -265,11 +266,23 @@ module.exports = (api, options) => {
265
266
console . log ( `$WEBPACK_DEV_SERVER_URL=${ server . url } ` )
266
267
} else {
267
268
// Launch electron with execa
268
- console . log ( '\nLaunching Electron...' )
269
+ if ( mainProcessArgs ) {
270
+ console . log (
271
+ '\nLaunching Electron with arguments: ' +
272
+ mainProcessArgs . join ( ' ' ) +
273
+ ' ...'
274
+ )
275
+ } else {
276
+ console . log ( '\nLaunching Electron...' )
277
+ }
269
278
child = execa (
270
279
require ( 'electron' ) ,
271
- // Have it load the main process file built with webpack
272
- [ outputDir ] ,
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
+ ] ,
273
286
{
274
287
cwd : api . resolve ( '.' ) ,
275
288
env : {
You can’t perform that action at this time.
0 commit comments