@@ -43,17 +43,43 @@ function parsePrevSourceMap(
43
43
return undefined ;
44
44
}
45
45
46
+ function getLoaderOptions ( _that : LoaderContext < LoaderOptions > ) : LoaderOptions {
47
+ // 3.x.x removed `getOptions` need to use `this.getOptions`
48
+ if ( typeof getOptions === 'function' ) {
49
+ // 1.x.x return null if empty query
50
+ // 2.x.x return empty object if empty query
51
+ return getOptions ( _that ) || { } ;
52
+ }
53
+
54
+ if ( typeof _that . getOptions === 'function' ) {
55
+ const rawOptions :LoaderOptions = _that . getOptions ( ) || { } ;
56
+
57
+ // `loader-utils` has specific behavior for parsing query strings
58
+ // (true, false and null won't be parsed as string but as a primitive value)
59
+ // https://webpack.js.org/migrate/5/#getoptions-method-for-loaders
60
+ Object . keys ( rawOptions ) . forEach ( ( key ) => {
61
+ const value = rawOptions [ key as keyof LoaderOptions ] ;
62
+
63
+ if ( [ 'false' , 'true' , 'null' ] . includes ( value as string ) ) {
64
+ rawOptions [ key as keyof LoaderOptions ] = JSON . parse ( value as string ) ;
65
+ }
66
+ } ) ;
67
+
68
+ return rawOptions ;
69
+ }
70
+
71
+ return { } ;
72
+ }
73
+
46
74
function cleanCssLoader (
47
75
this : LoaderContext < LoaderOptions > ,
48
76
content : string | Buffer ,
49
77
prevSourceMap ?: string | SourceMap ,
50
78
additionalData ?: AdditionalData
51
79
) : void {
52
80
const callback = this . async ( ) ;
53
- // 1.x.x return null if empty query
54
- // 2.x.x return empty object if empty query
55
- // 3.x.x removed `getOptions` need to use `this.getOptions`
56
- const loaderOptions = ( typeof this . getOptions === 'function' ? this . getOptions ( ) : getOptions ?.( this ) ) || { } ;
81
+
82
+ const loaderOptions = getLoaderOptions ( this ) ;
57
83
58
84
validate ( schema as JSONSchema7 , loaderOptions , {
59
85
name : "clean-css-loader" ,
0 commit comments