From 9b04362e12597b272da166e66fbd650223494e3f Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Sat, 16 Dec 2023 17:11:27 +0800 Subject: [PATCH] feat: support for passing arguments to `electron` in `dev` and `preview` commands (#339) --- src/cli.ts | 8 ++++++++ src/electron.ts | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli.ts b/src/cli.ts index 6938df7..a4f4f9c 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -97,6 +97,10 @@ cli process.env.NO_SANDBOX = '1' } + if (options['--']) { + process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--']); + } + if (options.entry) { process.env.ELECTRON_ENTRY = options.entry } @@ -151,6 +155,10 @@ cli process.env.ELECTRON_ENTRY = options.entry } + if (options['--']) { + process.env.ELECTRON_CLI_ARGS = JSON.stringify(options['--']); + } + try { await preview(inlineConfig, { skipBuild: options.skipBuild }) } catch (e) { diff --git a/src/electron.ts b/src/electron.ts index c5f5a2c..436bd6e 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -125,7 +125,7 @@ export function startElectron(root: string | undefined): ChildProcess { const isDev = process.env.NODE_ENV_ELECTRON_VITE === 'development' - const args: string[] = [] + const args: string[] = process.env.ELECTRON_CLI_ARGS ? JSON.parse(process.env.ELECTRON_CLI_ARGS) : [] if (!!process.env.REMOTE_DEBUGGING_PORT && isDev) { args.push(`--remote-debugging-port=${process.env.REMOTE_DEBUGGING_PORT}`)