Skip to content

Commit

Permalink
feat(css): use esbuild.log* options when minifying (#9210)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Jul 19, 2022
1 parent af6088f commit 88baa53
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1249,18 +1249,25 @@ async function minifyCSS(css: string, config: ResolvedConfig) {
function resolveEsbuildMinifyOptions(
options: ESBuildOptions
): TransformOptions {
const base: TransformOptions = {
logLevel: options.logLevel,
logLimit: options.logLimit,
logOverride: options.logOverride
}

if (
options.minifyIdentifiers != null ||
options.minifySyntax != null ||
options.minifyWhitespace != null
) {
return {
...base,
minifyIdentifiers: options.minifyIdentifiers ?? true,
minifySyntax: options.minifySyntax ?? true,
minifyWhitespace: options.minifyWhitespace ?? true
}
} else {
return { minify: true }
return { ...base, minify: true }
}
}

Expand Down
7 changes: 7 additions & 0 deletions playground/css/__tests__/css.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,10 @@ test('aliased css has content', async () => {
// expect(await page.textContent('.aliased-content')).toMatch('.aliased')
expect(await getColor('.aliased-module')).toBe('blue')
})

test.runIf(isBuild)('warning can be suppressed by esbuild.logOverride', () => {
serverLogs.forEach((log) => {
// no warning from esbuild css minifier
expect(log).not.toMatch('unsupported-css-property')
})
})
2 changes: 2 additions & 0 deletions playground/css/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ import aliasModule from '#alias-module'
document
.querySelector('.aliased-module')
.classList.add(aliasModule.aliasedModule)

import './unsupported.css'
3 changes: 3 additions & 0 deletions playground/css/unsupported.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.unsupported {
overflow-x: hidden;
}
5 changes: 5 additions & 0 deletions playground/css/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ module.exports = {
build: {
cssTarget: 'chrome61'
},
esbuild: {
logOverride: {
'unsupported-css-property': 'silent'
}
},
resolve: {
alias: {
'@': __dirname,
Expand Down

0 comments on commit 88baa53

Please sign in to comment.