perf: spawn Electron process using parent's stdios (#236)
This commit is contained in:
parent
9d76799072
commit
342a0556cd
|
@ -1,8 +1,7 @@
|
|||
import path from 'node:path'
|
||||
import fs from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { type ChildProcessWithoutNullStreams, spawn } from 'node:child_process'
|
||||
import { type Logger } from 'vite'
|
||||
import { type ChildProcess, spawn } from 'node:child_process'
|
||||
|
||||
const _require = createRequire(import.meta.url)
|
||||
|
||||
|
@ -111,13 +110,11 @@ export function getElectronChromeTarget(): string {
|
|||
return ''
|
||||
}
|
||||
|
||||
export function startElectron(root: string | undefined, logger: Logger): ChildProcessWithoutNullStreams {
|
||||
export function startElectron(root: string | undefined): ChildProcess {
|
||||
ensureElectronEntryFile(root)
|
||||
|
||||
const electronPath = getElectronPath()
|
||||
|
||||
const inspect = !!process.env.VSCODE_INSPECTOR_OPTIONS
|
||||
|
||||
const isDev = process.env.NODE_ENV_ELECTRON_VITE === 'development'
|
||||
|
||||
const args: string[] = []
|
||||
|
@ -134,13 +131,7 @@ export function startElectron(root: string | undefined, logger: Logger): ChildPr
|
|||
args.push(`--inspect-brk=${process.env.V8_INSPECTOR_BRK_PORT}`)
|
||||
}
|
||||
|
||||
const ps = spawn(electronPath, ['.'].concat(args))
|
||||
ps.stdout.on('data', chunk => {
|
||||
!inspect && chunk.toString().trim() && logger.info(chunk.toString())
|
||||
})
|
||||
ps.stderr.on('data', chunk => {
|
||||
!inspect && chunk.toString().trim() && logger.error(chunk.toString())
|
||||
})
|
||||
const ps = spawn(electronPath, ['.'].concat(args), { stdio: 'inherit' })
|
||||
ps.on('close', process.exit)
|
||||
|
||||
return ps
|
||||
|
|
|
@ -11,7 +11,7 @@ export async function preview(inlineConfig: InlineConfig = {}, options: { skipBu
|
|||
|
||||
const logger = createLogger(inlineConfig.logLevel)
|
||||
|
||||
startElectron(inlineConfig.root, logger)
|
||||
startElectron(inlineConfig.root)
|
||||
|
||||
logger.info(colors.green(`\nstart electron app...\n`))
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { ChildProcessWithoutNullStreams } from 'node:child_process'
|
||||
import type { ChildProcess } from 'node:child_process'
|
||||
import {
|
||||
type UserConfig as ViteConfig,
|
||||
type ViteDevServer,
|
||||
|
@ -22,7 +22,7 @@ export async function createServer(
|
|||
const logger = createLogger(inlineConfig.logLevel)
|
||||
|
||||
let server: ViteDevServer | undefined
|
||||
let ps: ChildProcessWithoutNullStreams | undefined
|
||||
let ps: ChildProcess | undefined
|
||||
|
||||
const mainViteConfig = config.config?.main
|
||||
if (mainViteConfig && !options.rendererOnly) {
|
||||
|
@ -34,7 +34,7 @@ export async function createServer(
|
|||
|
||||
ps.removeAllListeners()
|
||||
ps.kill()
|
||||
ps = startElectron(inlineConfig.root, logger)
|
||||
ps = startElectron(inlineConfig.root)
|
||||
|
||||
logger.info(colors.green(`\nrestart electron app...`))
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ export async function createServer(
|
|||
server.printUrls()
|
||||
}
|
||||
|
||||
ps = startElectron(inlineConfig.root, logger)
|
||||
ps = startElectron(inlineConfig.root)
|
||||
|
||||
logger.info(colors.green(`\nstart electron app...\n`))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue