From b071180ec3c5148f8f7e2096b82fbe4bd1b9e77f Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 2 Jan 2025 11:55:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(web):=20=E4=BF=AE=E5=A4=8D=20HBuilderX=20?= =?UTF-8?q?=E4=B8=AD=E9=A2=84=E7=BC=96=E8=AF=91=E5=99=A8=E5=AE=89=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/vite-plugin-uni/src/cli/action.ts | 9 ++++++++- packages/vite-plugin-uni/src/configResolved/index.ts | 8 ++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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 }