1
+ // @deno -types="https://deno.land/x/[email protected] /mod.d.ts"
2
+ import { build } from 'https://deno.land/x/[email protected] /mod.js'
1
3
import util from '../shared/util.ts'
2
4
import { PostCSSPlugin , CSSOptions } from '../types.ts'
3
5
@@ -8,7 +10,6 @@ export class CSSProcessor {
8
10
#isProd: boolean
9
11
#options: Required < CSSOptions >
10
12
#postcss: any
11
- #cleanCSS: any
12
13
#modulesJSON: Record < string , Record < string , string > >
13
14
14
15
constructor ( ) {
@@ -18,7 +19,6 @@ export class CSSProcessor {
18
19
postcss : { plugins : [ 'autoprefixer' ] } ,
19
20
}
20
21
this . #postcss = null
21
- this . #cleanCSS = null
22
22
this . #modulesJSON = { }
23
23
}
24
24
@@ -64,17 +64,26 @@ export class CSSProcessor {
64
64
}
65
65
66
66
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 )
73
68
}
74
69
75
70
const { content : pcss } = await this . #postcss. process ( content , { from : url } ) . async ( )
76
71
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
+ }
78
87
79
88
if ( url . startsWith ( '#inline-style-' ) ) {
80
89
return {
0 commit comments