perf: dev error message

This commit is contained in:
alex8088 2023-12-14 20:49:22 +08:00
parent dbd7b0137b
commit 7b27e684d6

View file

@ -24,6 +24,10 @@ export async function createServer(
let server: ViteDevServer | undefined let server: ViteDevServer | undefined
let ps: ChildProcess | undefined let ps: ChildProcess | undefined
const errorHook = (e): void => {
logger.error(`${colors.bgRed(colors.white(' ERROR '))} ${colors.red(e.message)}`)
}
const mainViteConfig = config.config?.main const mainViteConfig = config.config?.main
if (mainViteConfig && !options.rendererOnly) { if (mainViteConfig && !options.rendererOnly) {
const watchHook = (): void => { const watchHook = (): void => {
@ -40,7 +44,7 @@ export async function createServer(
} }
} }
await doBuild(mainViteConfig, watchHook) await doBuild(mainViteConfig, watchHook, errorHook)
logger.info(colors.green(`\nbuild the electron main process successfully`)) logger.info(colors.green(`\nbuild the electron main process successfully`))
} }
@ -59,7 +63,7 @@ export async function createServer(
} }
} }
await doBuild(preloadViteConfig, watchHook) await doBuild(preloadViteConfig, watchHook, errorHook)
logger.info(colors.green(`\nbuild the electron preload files successfully`)) logger.info(colors.green(`\nbuild the electron preload files successfully`))
} }
@ -108,7 +112,7 @@ export async function createServer(
type UserConfig = ViteConfig & { configFile?: string | false } type UserConfig = ViteConfig & { configFile?: string | false }
async function doBuild(config: UserConfig, watchHook: () => void): Promise<void> { async function doBuild(config: UserConfig, watchHook: () => void, errorHook: (e: Error) => void): Promise<void> {
return new Promise(resolve => { return new Promise(resolve => {
if (config.build?.watch) { if (config.build?.watch) {
let firstBundle = true let firstBundle = true
@ -131,10 +135,12 @@ async function doBuild(config: UserConfig, watchHook: () => void): Promise<void>
}) })
} }
viteBuild(config).then(() => { viteBuild(config)
if (!config.build?.watch) { .then(() => {
resolve() if (!config.build?.watch) {
} resolve()
}) }
})
.catch(e => errorHook(e))
}) })
} }