@@ -81,6 +81,7 @@ const cssRegex = /\.css$/;
81
81
const cssModuleRegex = / \. m o d u l e \. c s s $ / ;
82
82
const sassRegex = / \. ( s c s s | s a s s ) $ / ;
83
83
const sassModuleRegex = / \. m o d u l e \. ( s c s s | s a s s ) $ / ;
84
+ const lessRegex = / \. l e s s $ / ;
84
85
85
86
const hasJsxRuntime = ( ( ) => {
86
87
if ( process . env . DISABLE_NEW_JSX_TRANSFORM === 'true' ) {
@@ -115,7 +116,7 @@ module.exports = function (webpackEnv) {
115
116
const shouldUseReactRefresh = env . raw . FAST_REFRESH ;
116
117
117
118
// common function to get style loaders
118
- const getStyleLoaders = ( cssOptions , preProcessor ) => {
119
+ const getStyleLoaders = ( cssOptions , preProcessor , preProcessorOptions = { } ) => {
119
120
const loaders = [
120
121
isEnvDevelopment && require . resolve ( 'style-loader' ) ,
121
122
isEnvProduction && {
@@ -188,6 +189,7 @@ module.exports = function (webpackEnv) {
188
189
{
189
190
loader : require . resolve ( preProcessor ) ,
190
191
options : {
192
+ ...preProcessorOptions ,
191
193
sourceMap : true ,
192
194
} ,
193
195
}
@@ -582,6 +584,35 @@ module.exports = function (webpackEnv) {
582
584
'sass-loader'
583
585
) ,
584
586
} ,
587
+ // Adds support for Less (using .less extensions)
588
+ {
589
+ test : lessRegex ,
590
+ use : getStyleLoaders (
591
+ {
592
+ importLoaders : 3 ,
593
+ sourceMap : isEnvProduction
594
+ ? shouldUseSourceMap
595
+ : isEnvDevelopment ,
596
+ modules : {
597
+ mode : 'icss' ,
598
+ } ,
599
+ } ,
600
+ 'less-loader' ,
601
+ {
602
+ lessOptions : {
603
+ javascriptEnabled : true ,
604
+ modifyVars : {
605
+ '@primary-color' : '#722ed1'
606
+ } ,
607
+ }
608
+ }
609
+ ) ,
610
+ // Don't consider CSS imports dead code even if the
611
+ // containing package claims to have no side effects.
612
+ // Remove this when webpack adds a warning or an error for this.
613
+ // See https://github.com/webpack/webpack/issues/6571
614
+ sideEffects : true ,
615
+ } ,
585
616
// "file" loader makes sure those assets get served by WebpackDevServer.
586
617
// When you `import` an asset, you get its (virtual) filename.
587
618
// In production, they would get copied to the `build` folder.
0 commit comments