@@ -43,17 +43,43 @@ function parsePrevSourceMap(
4343 return undefined ;
4444}
4545
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+
4674function cleanCssLoader (
4775 this : LoaderContext < LoaderOptions > ,
4876 content : string | Buffer ,
4977 prevSourceMap ?: string | SourceMap ,
5078 additionalData ?: AdditionalData
5179) : void {
5280 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 ) ;
5783
5884 validate ( schema as JSONSchema7 , loaderOptions , {
5985 name : "clean-css-loader" ,
0 commit comments