1.首先在項(xiàng)目根目錄下載less和less-loader
yarn add less less-loader
2.暴露webpack配置文件
yarn eject
3.找到config目錄下的webpack.config.js文件
因?yàn)镽eact默認(rèn)支持sass辩涝,所以只需要把sass的配置方法復(fù)制一份改成less然后重啟項(xiàng)目就行了舟陆。
首先搜索:const sass
然后加上
const lessRegex = /\.less$/;
const lessModuleRegex = /\.module\.less$/;
結(jié)果如圖
接著搜索:test: sass
然后在后面加上
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'less-loader'
),
sideEffects: true,
},
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'less-loader'
),
},
接著重啟項(xiàng)目就好了