yarn add less less-loader -D
yarn eject
在webpack.config.js文件中
const sassRegex = /.(scss|sass)$/;
const sassModuleRegex = /.module.(scss|sass)$/;
在下面新增两条
const lessRegex = /.less$/;
const lessModuleRegex = /.module.less$/;
{
test: sassRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'sass-loader'
),
sideEffects: true,
},
//对应的增加一条
{
test: lessRegex,
exclude: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'less-loader'
),
sideEffects: true,
},
{
test: sassModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'sass-loader'
),
},
//对应的增加一条
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: true,
getLocalIdent: getCSSModuleLocalIdent,
},
'less-loader'
),
},
运行的时候发现Error: Cannot find module '@babel/core'错误
//更新到最新版本就可以了
npm install -D babel-loader @babel/core @babel/preset-env webpack
////////////////////////////////////////////............................................................................................................................................................................../////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////############################################################################################################################################################################################################################################################