Skip to content

Commit

Permalink
fix(css): use esbuild legalComments config when minifying CSS (#13661)
Browse files Browse the repository at this point in the history
  • Loading branch information
niksy authored Jun 30, 2023
1 parent 6fe1491 commit 2d9008e
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 1 deletion.
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.

0 comments on commit 2d9008e

Please sign in to comment.