diff --git a/src/cli.ts b/src/cli.ts index 209f0b2..02fbee3 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -31,9 +31,15 @@ interface DevCLIOptions { inspect?: boolean | string inspectBrk?: boolean | string remoteDebuggingPort?: string + noSandbox?: boolean rendererOnly?: boolean } +interface PreviewCLIOptions { + noSandbox?: boolean + skipBuild?: boolean +} + function createInlineConfig(root: string, options: GlobalCLIOptions): InlineConfig { return { root, @@ -71,6 +77,7 @@ cli .option('--inspect [port]', `[boolean | number] enable V8 inspector on the specified port`) .option('--inspectBrk [port]', `[boolean | number] enable V8 inspector on the specified port`) .option('--remoteDebuggingPort ', `[string] port for remote debugging`) + .option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`) .option('--rendererOnly', `[boolean] only dev server for the renderer`) .action(async (root: string, options: DevCLIOptions & GlobalCLIOptions) => { if (options.remoteDebuggingPort) { @@ -85,6 +92,10 @@ cli process.env.V8_INSPECTOR_BRK_PORT = typeof options.inspectBrk === 'number' ? `${options.inspectBrk}` : '5858' } + if (options.noSandbox) { + process.env.NO_SANDBOX = '1' + } + if (options.entry) { process.env.ELECTRON_ENTRY = options.entry } @@ -125,11 +136,16 @@ cli.command('build [root]', 'build for production').action(async (root: string, // preview cli .command('preview [root]', 'start electron app to preview production build') + .option('--noSandbox', `[boolean] forces renderer process to run un-sandboxed`) .option('--skipBuild', `[boolean] skip build`) - .action(async (root: string, options: { skipBuild?: boolean } & GlobalCLIOptions) => { + .action(async (root: string, options: PreviewCLIOptions & GlobalCLIOptions) => { const { preview } = await import('./preview') const inlineConfig = createInlineConfig(root, options) + if (options.noSandbox) { + process.env.NO_SANDBOX = '1' + } + if (options.entry) { process.env.ELECTRON_ENTRY = options.entry } diff --git a/src/electron.ts b/src/electron.ts index 45925c5..d6e5f3c 100644 --- a/src/electron.ts +++ b/src/electron.ts @@ -136,6 +136,10 @@ export function startElectron(root: string | undefined): ChildProcess { args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`) } + if (process.env.NO_SANDBOX === '1') { + args.push('--no-sandbox') + } + const entry = process.env.ELECTRON_ENTRY || '.' const ps = spawn(electronPath, [entry].concat(args), { stdio: 'inherit' })