diff --git a/packages/vite-plugin-uni/src/cli/action.ts b/packages/vite-plugin-uni/src/cli/action.ts index 955cc3fb327..d66fb981d59 100644 --- a/packages/vite-plugin-uni/src/cli/action.ts +++ b/packages/vite-plugin-uni/src/cli/action.ts @@ -23,6 +23,7 @@ import { import { initEasycom } from '../utils/easycom' import { runUVueAndroidBuild, runUVueAndroidDev } from './uvue' import type { FSWatcher } from 'chokidar' +import { initLogger } from '../configResolved' export async function runDev(options: CliOptions & ServerOptions) { extend(options, { @@ -178,7 +179,13 @@ export async function runBuild(options: CliOptions & BuildOptions) { process.exit(0) } } catch (e: any) { - console.error(e.message || e) + if (isInHBuilderX()) { + initLogger({ + logger: createLogger(options.logLevel), + }).error(e.message || e) + } else { + console.error(e.message || e) + } console.error(`Build failed with errors.`) process.exit(1) } diff --git a/packages/vite-plugin-uni/src/configResolved/index.ts b/packages/vite-plugin-uni/src/configResolved/index.ts index 491f970fc01..571986904b1 100644 --- a/packages/vite-plugin-uni/src/configResolved/index.ts +++ b/packages/vite-plugin-uni/src/configResolved/index.ts @@ -1,4 +1,4 @@ -import type { Plugin, ResolvedConfig } from 'vite' +import type { Logger, Plugin } from 'vite' import { extend, isString } from '@vue/shared' import { checkUpdate, @@ -53,7 +53,10 @@ function initCheckUpdate() { export function initLogger({ logger, nvue, -}: ResolvedConfig & { nvue?: boolean }) { +}: { + logger: Logger + nvue?: boolean +}) { const { info, warn, error } = logger logger.info = (msg, opts) => { msg = formatInfoMsg(msg, extend(opts || {}, { nvue })) @@ -73,4 +76,5 @@ export function initLogger({ return error(msg, opts) } } + return logger }