Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 35e74da

Browse files
committed
Use esbuild minify css instead of cleanCSS
1 parent de4f5af commit 35e74da

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

server/css.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// @deno-types="https://deno.land/x/[email protected]/mod.d.ts"
2+
import { build } from 'https://deno.land/x/[email protected]/mod.js'
13
import util from '../shared/util.ts'
24
import { PostCSSPlugin, CSSOptions } from '../types.ts'
35

@@ -8,7 +10,6 @@ export class CSSProcessor {
810
#isProd: boolean
911
#options: Required<CSSOptions>
1012
#postcss: any
11-
#cleanCSS: any
1213
#modulesJSON: Record<string, Record<string, string>>
1314

1415
constructor() {
@@ -18,7 +19,6 @@ export class CSSProcessor {
1819
postcss: { plugins: ['autoprefixer'] },
1920
}
2021
this.#postcss = null
21-
this.#cleanCSS = null
2222
this.#modulesJSON = {}
2323
}
2424

@@ -64,17 +64,26 @@ export class CSSProcessor {
6464
}
6565

6666
if (this.#postcss == null) {
67-
const [postcss, cleanCSS] = await Promise.all([
68-
initPostCSS(this.#options.postcss.plugins),
69-
this.#isProd ? initCleanCSS() : Promise.resolve(null)
70-
])
71-
this.#postcss = postcss
72-
this.#cleanCSS = cleanCSS
67+
this.#postcss = await initPostCSS(this.#options.postcss.plugins)
7368
}
7469

7570
const { content: pcss } = await this.#postcss.process(content, { from: url }).async()
7671
const modulesJSON = this.getModulesJSON(url)
77-
const css = this.#isProd ? this.#cleanCSS.minify(pcss).styles : pcss
72+
73+
let css = pcss
74+
if (this.#isProd) {
75+
const ret = await build({
76+
stdin: {
77+
loader: 'css',
78+
sourcefile: url,
79+
contents: pcss
80+
},
81+
minify: true,
82+
write: false,
83+
sourcemap: false,
84+
})
85+
css = ret.outputFiles[0].text
86+
}
7887

7988
if (url.startsWith('#inline-style-')) {
8089
return {

0 commit comments

Comments
 (0)