Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: format css minify esbuild error #7731

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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