From c4450757d4c87de671a985714139d17349f905d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Thu, 14 Apr 2022 23:16:14 +0900 Subject: [PATCH] chore: format css minify esbuild error (#7731) --- packages/vite/src/node/plugins/css.ts | 31 +++++++++++++++++---------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 0a14e091c53637..2f5ab3df58b46a 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -1092,18 +1092,27 @@ async function doImportCSSReplace( } async function minifyCSS(css: string, config: ResolvedConfig) { - const { code, warnings } = await transform(css, { - loader: 'css', - minify: true, - target: config.build.cssTarget || undefined - }) - if (warnings.length) { - const msgs = await formatMessages(warnings, { kind: 'warning' }) - config.logger.warn( - colors.yellow(`warnings when minifying css:\n${msgs.join('\n')}`) - ) + try { + const { code, warnings } = await transform(css, { + loader: 'css', + minify: true, + target: config.build.cssTarget || undefined + }) + if (warnings.length) { + const msgs = await formatMessages(warnings, { kind: 'warning' }) + config.logger.warn( + colors.yellow(`warnings when minifying css:\n${msgs.join('\n')}`) + ) + } + return code + } catch (e) { + if (e.errors) { + const msgs = await formatMessages(e.errors, { kind: 'error' }) + e.frame = '\n' + msgs.join('\n') + e.loc = e.errors[0].location + } + throw e } - return code } export async function hoistAtRules(css: string) {