Skip to content

Commit 2d9008e

Browse files
authored
fix(css): use esbuild legalComments config when minifying CSS (#13661)
1 parent 6fe1491 commit 2d9008e

File tree

10 files changed

+37
-1
lines changed

10 files changed

+37
-1
lines changed

packages/vite/src/node/plugins/css.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,7 @@ function resolveMinifyCssEsbuildOptions(
15211521
logLevel: options.logLevel,
15221522
logLimit: options.logLimit,
15231523
logOverride: options.logOverride,
1524+
legalComments: options.legalComments,
15241525
}
15251526

15261527
if (

playground/minify/__tests__/minify.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@ test.runIf(isBuild)('no minifySyntax', () => {
1414
const cssContent = readFile(path.resolve(assetsDir, cssFile))
1515

1616
expect(jsContent).toContain('{console.log("hello world")}')
17+
expect(jsContent).not.toContain('/*! explicit comment */')
18+
1719
expect(cssContent).toContain('color:#ff0000')
20+
expect(cssContent).not.toContain('/*! explicit comment */')
1821
})
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/*! explicit comment */
2+
h2 {
3+
color: #ff00ff;
4+
}

playground/minify/dir/module/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/*! explicit comment */
2+
export const msg = `[success] minified module`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@vitejs/test-minify",
3+
"private": true,
4+
"type": "module",
5+
"version": "0.0.0"
6+
}

playground/minify/main.js

+3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import './test.css'
2+
import { msg } from 'minified-module'
3+
4+
console.log(msg)
25

36
if (window) {
47
console.log('hello world')

playground/minify/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
"build": "vite build",
99
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
1010
"preview": "vite preview"
11+
},
12+
"dependencies": {
13+
"minified-module": "file:./dir/module"
1114
}
1215
}

playground/minify/test.css

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import 'minified-module/index.css';
2+
13
h1 {
24
/* do not minify as red text */
35
color: #ff0000;

playground/minify/vite.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from 'vite'
22

33
export default defineConfig({
44
esbuild: {
5+
legalComments: 'none',
56
minifySyntax: false,
67
},
78
})

pnpm-lock.yaml

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)