@@ -4,7 +4,7 @@ import defaults from 'lodash/defaults'
4
4
import loaderUtils from 'loader-utils'
5
5
import debug from '../core/debug'
6
6
import type { Compiler } from '../interfaces'
7
- import { cssRequiresTransform , isJsx } from '../core/utils'
7
+ import { isJsx , transformCSS } from '../core/utils'
8
8
9
9
function TransformTemplate (
10
10
this : webpack . loader . LoaderContext ,
@@ -22,13 +22,8 @@ function TransformTemplate(
22
22
/*
23
23
* Via the pitcher loader we can transfer post-interpreted CSS
24
24
*/
25
- if ( this . resource . indexOf ( 'type=style' ) > 0 ) {
26
- // if no transform is required
27
- if ( ! cssRequiresTransform ( source ) )
28
- return source
29
-
30
- return service . transformCSS ( source , this . resource )
31
- }
25
+ if ( this . resource . indexOf ( 'type=style' ) > 0 )
26
+ return transformCSS ( service , source , this . resource )
32
27
33
28
const hasHtmlWebpackPlugin = this . loaders . filter ( ( loader ) => {
34
29
// loader name as unresolved module
@@ -62,9 +57,6 @@ function TransformTemplate(
62
57
debug . loader ( 'Template has unsupported block, skipping resource' , this . resource )
63
58
return match
64
59
}
65
- if ( ! cssRequiresTransform ( match ) )
66
- return match
67
-
68
60
// for jsx styles we need to replace the contents of template strings
69
61
if ( isJsx ( css ) ) {
70
62
let m , transformedCSS
@@ -77,14 +69,16 @@ function TransformTemplate(
77
69
// The result can be accessed through the `m`-variable.
78
70
m . forEach ( ( match , groupIndex ) => {
79
71
if ( groupIndex === 1 ) {
80
- transformedCSS = `<style${ meta } >\n{\`${ service . transformCSS ( match , this . resource ) } \n\`}</style>`
72
+ const transformedJSXCSS = transformCSS ( service , match , this . resource )
73
+ transformedCSS = `<style${ meta } >\n{\`${ transformedJSXCSS } \n\`}</style>`
81
74
debug . loader ( 'jsx transformed' , transformedCSS )
82
75
}
83
76
} )
84
77
}
85
78
return transformedCSS ?? match
86
79
}
87
- return `<style${ meta } >\n${ service . transformCSS ( css , this . resource ) } \n</style>`
80
+ const transformedCSS = transformCSS ( service , css , this . resource )
81
+ return `<style${ meta } >\n${ transformedCSS } \n</style>`
88
82
} )
89
83
debug . loader ( 'Transformed template ' , this . resource )
90
84
const transformed = service . transformGroups ( templateWithTransformedCSS )
@@ -94,7 +88,7 @@ function TransformTemplate(
94
88
output = templateWithTransformedCSS
95
89
}
96
90
catch ( e ) {
97
- this . emitWarning ( `[Windi CSS ] Failed to transform groups and css for template: ${ this . resource } .` )
91
+ this . emitWarning ( `[WindiCSS ] Failed to transform groups and css for template: ${ this . resource } .` )
98
92
}
99
93
return output
100
94
}
0 commit comments