@@ -24,45 +24,49 @@ const ignoreWarningsConfig = {
24
24
} ;
25
25
26
26
const scssConfigIndex = baseClientWebpackConfig . module . rules . findIndex ( ( config ) =>
27
- '.scss' . match ( config . test ) ,
27
+ '.scss' . match ( config . test ) && config . use ,
28
28
) ;
29
29
30
- // Configure sass-loader to use the modern API
31
- const scssRule = baseClientWebpackConfig . module . rules [ scssConfigIndex ] ;
32
- const sassLoaderIndex = scssRule . use . findIndex ( ( loader ) => {
33
- if ( typeof loader === 'string' ) {
34
- return loader . includes ( 'sass-loader' ) ;
35
- }
36
- return loader . loader && loader . loader . includes ( 'sass-loader' ) ;
37
- } ) ;
30
+ if ( scssConfigIndex === - 1 ) {
31
+ console . warn ( 'No SCSS rule with use array found in webpack config' ) ;
32
+ } else {
33
+ // Configure sass-loader to use the modern API
34
+ const scssRule = baseClientWebpackConfig . module . rules [ scssConfigIndex ] ;
35
+ const sassLoaderIndex = scssRule . use . findIndex ( ( loader ) => {
36
+ if ( typeof loader === 'string' ) {
37
+ return loader . includes ( 'sass-loader' ) ;
38
+ }
39
+ return loader . loader && loader . loader . includes ( 'sass-loader' ) ;
40
+ } ) ;
38
41
39
- if ( sassLoaderIndex !== - 1 ) {
40
- const sassLoader = scssRule . use [ sassLoaderIndex ] ;
41
- if ( typeof sassLoader === 'string' ) {
42
- scssRule . use [ sassLoaderIndex ] = {
43
- loader : sassLoader ,
44
- options : {
45
- api : 'modern'
46
- }
47
- } ;
48
- } else {
49
- sassLoader . options = sassLoader . options || { } ;
50
- sassLoader . options . api = 'modern' ;
42
+ if ( sassLoaderIndex !== - 1 ) {
43
+ const sassLoader = scssRule . use [ sassLoaderIndex ] ;
44
+ if ( typeof sassLoader === 'string' ) {
45
+ scssRule . use [ sassLoaderIndex ] = {
46
+ loader : sassLoader ,
47
+ options : {
48
+ api : 'modern'
49
+ }
50
+ } ;
51
+ } else {
52
+ sassLoader . options = sassLoader . options || { } ;
53
+ sassLoader . options . api = 'modern' ;
54
+ }
51
55
}
52
- }
53
56
54
- // Fix css-loader configuration for CSS modules if namedExport is enabled
55
- // When namedExport is true, exportLocalsConvention must be camelCaseOnly or dashesOnly
56
- const cssLoader = scssRule . use . find ( loader => {
57
- const loaderName = typeof loader === 'string' ? loader : loader ?. loader ;
58
- return loaderName ?. includes ( 'css-loader' ) ;
59
- } ) ;
57
+ // Fix css-loader configuration for CSS modules if namedExport is enabled
58
+ // When namedExport is true, exportLocalsConvention must be camelCaseOnly or dashesOnly
59
+ const cssLoader = scssRule . use . find ( ( loader ) => {
60
+ const loaderName = typeof loader === 'string' ? loader : loader ?. loader ;
61
+ return loaderName ?. includes ( 'css-loader' ) ;
62
+ } ) ;
60
63
61
- if ( cssLoader ?. options ?. modules ?. namedExport ) {
62
- cssLoader . options . modules . exportLocalsConvention = 'camelCaseOnly' ;
63
- }
64
+ if ( cssLoader ?. options ?. modules ?. namedExport ) {
65
+ cssLoader . options . modules . exportLocalsConvention = 'camelCaseOnly' ;
66
+ }
64
67
65
- baseClientWebpackConfig . module . rules [ scssConfigIndex ] . use . push ( sassLoaderConfig ) ;
68
+ baseClientWebpackConfig . module . rules [ scssConfigIndex ] . use . push ( sassLoaderConfig ) ;
69
+ }
66
70
67
71
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals
68
72
const commonWebpackConfig = ( ) => merge ( { } , baseClientWebpackConfig , commonOptions , ignoreWarningsConfig ) ;
0 commit comments