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+
13export class CSS {
24 private readonly styles = new Map < string , string > ( )
35
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' , '' ) )
619 return ''
720 }
821
Original file line number Diff line number Diff line change @@ -97,13 +97,7 @@ export default function UserscriptPlugin(
9797 let code = src
9898
9999 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 )
107101 }
108102
109103 if ( path . includes ( config . entry ) ) {
Original file line number Diff line number Diff line change @@ -20,15 +20,15 @@ const style2 = `
2020
2121test ( 'snapshot css modules' , async ( ) => {
2222 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 )
2525 css . merge ( [ '/style2.css' ] )
2626 expect ( css . inject ( ) ) . toMatchSnapshot ( )
2727} )
2828
2929test ( 'snapshot css modules (undefined)' , async ( ) => {
3030 const css = new CSS ( )
31- await css . add ( style1 , '/style1.css' )
31+ await css . add ( '/style1.css' , style1 , true )
3232 css . merge ( [ ] )
3333 expect ( css . inject ( ) ) . toMatchSnapshot ( )
3434} )
You can’t perform that action at this time.
0 commit comments