File tree Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Expand file tree Collapse file tree 3 files changed +19
-12
lines changed Original file line number Diff line number Diff line change
1
+ import { transform } from './helpers.js'
2
+
1
3
export class CSS {
2
4
private readonly styles = new Map < string , string > ( )
3
5
4
- add ( path : string , styles : string ) : string {
5
- this . styles . set ( path , styles . replace ( '\n' , '' ) )
6
+ async add (
7
+ name : string ,
8
+ file : string ,
9
+ isBuildWatch : boolean
10
+ ) : Promise < string > {
11
+ const styles = await transform ( {
12
+ name,
13
+ file,
14
+ minify : isBuildWatch ,
15
+ loader : 'css'
16
+ } )
17
+
18
+ this . styles . set ( name , styles . replace ( '\n' , '' ) )
6
19
return ''
7
20
}
8
21
Original file line number Diff line number Diff line change @@ -97,13 +97,7 @@ export default function UserscriptPlugin(
97
97
let code = src
98
98
99
99
if ( regexpStyles . test ( path ) ) {
100
- const styles = await transform ( {
101
- minify : ! isBuildWatch ,
102
- file : code ,
103
- name : path ,
104
- loader : 'css'
105
- } )
106
- code = css . add ( path , styles )
100
+ code = await css . add ( path , code , ! isBuildWatch )
107
101
}
108
102
109
103
if ( path . includes ( config . entry ) ) {
Original file line number Diff line number Diff line change @@ -20,15 +20,15 @@ const style2 = `
20
20
21
21
test ( 'snapshot css modules' , async ( ) => {
22
22
const css = new CSS ( )
23
- await css . add ( style1 , '/style1.css' )
24
- await css . add ( style2 , '/style2.css' )
23
+ await css . add ( '/style1.css' , style1 , true )
24
+ await css . add ( '/style2.css' , style2 , true )
25
25
css . merge ( [ '/style2.css' ] )
26
26
expect ( css . inject ( ) ) . toMatchSnapshot ( )
27
27
} )
28
28
29
29
test ( 'snapshot css modules (undefined)' , async ( ) => {
30
30
const css = new CSS ( )
31
- await css . add ( style1 , '/style1.css' )
31
+ await css . add ( '/style1.css' , style1 , true )
32
32
css . merge ( [ ] )
33
33
expect ( css . inject ( ) ) . toMatchSnapshot ( )
34
34
} )
You can’t perform that action at this time.
0 commit comments