Skip to content

Commit

Permalink
chore: format css minify esbuild error (#7731)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 14, 2022
1 parent 6c27f14 commit c445075
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -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) {
Expand Down

0 comments on commit c445075

Please sign in to comment.