current position:Home>Use less and CSS modules in react scaffold Engineering

Use less and CSS modules in react scaffold Engineering

2022-06-24 07:53:02Zhangxiaolang

First exposure webpack Related configuration Execute the following code  

npm run eject

download less And less-loader I used yarn  You download it according to your situation

yarn add less less-loader

Enter the root directory config Medium webpack.config.js In profile stay sass-loader Add the following code after

Probably 493 Row or so  

 // Less  Parsing configuration 
            {
              test: lessRegex,
              exclude: lessModuleRegex,
              use: getStyleLoaders(
                {
                  importLoaders: 2,
                  sourceMap: isEnvProduction && shouldUseSourceMap,
                  modules: true,// Turn on 
                },
                'less-loader'
              ),
              sideEffects: true,
            },
            {
              test: lessModuleRegex,
              use: getStyleLoaders(
                {
                  importLoaders: 2,
                  sourceMap: isEnvProduction && shouldUseSourceMap,
                  modules: true,
                  getLocalIdent: getCSSModuleLocalIdent,
                },
                'less-loader'
              )
            },

among modules:true That is to say Turn on CSS Modules The place of  

copyright notice
author[Zhangxiaolang],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/175/202206240328340971.html

Random recommended