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

fix(css): use esbuild legalComments config when minifying CSS #13661

Merged
merged 1 commit into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,7 @@ function resolveMinifyCssEsbuildOptions(
logLevel: options.logLevel,
logLimit: options.logLimit,
logOverride: options.logOverride,
legalComments: options.legalComments,
}

if (
Expand Down
3 changes: 3 additions & 0 deletions playground/minify/__tests__/minify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ test.runIf(isBuild)('no minifySyntax', () => {
const cssContent = readFile(path.resolve(assetsDir, cssFile))

expect(jsContent).toContain('{console.log("hello world")}')
expect(jsContent).not.toContain('/*! explicit comment */')

expect(cssContent).toContain('color:#ff0000')
expect(cssContent).not.toContain('/*! explicit comment */')
})
4 changes: 4 additions & 0 deletions playground/minify/dir/module/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*! explicit comment */
h2 {
color: #ff00ff;
}
2 changes: 2 additions & 0 deletions playground/minify/dir/module/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/*! explicit comment */
export const msg = `[success] minified module`
6 changes: 6 additions & 0 deletions playground/minify/dir/module/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@vitejs/test-minify",
"private": true,
"type": "module",
"version": "0.0.0"
}
3 changes: 3 additions & 0 deletions playground/minify/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import './test.css'
import { msg } from 'minified-module'

console.log(msg)

if (window) {
console.log('hello world')
Expand Down
3 changes: 3 additions & 0 deletions playground/minify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@
"build": "vite build",
"debug": "node --inspect-brk ../../packages/vite/bin/vite",
"preview": "vite preview"
},
"dependencies": {
"minified-module": "file:./dir/module"
}
}
2 changes: 2 additions & 0 deletions playground/minify/test.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'minified-module/index.css';

h1 {
/* do not minify as red text */
color: #ff0000;
Expand Down
1 change: 1 addition & 0 deletions playground/minify/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from 'vite'

export default defineConfig({
esbuild: {
legalComments: 'none',
minifySyntax: false,
},
})
13 changes: 12 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.