// 添加 less 解析规则const lessRegex =/\.less$/;const lessModuleRegex =/\.module\.less$/;
再找到以下代码
// Adds support for CSS Modules (https://github.com/css-modules/css-modules)// using the extension .module.css{
test: cssModuleRegex,
use:getStyleLoaders({
importLoaders:1,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules:{
getLocalIdent: getCSSModuleLocalIdent,},}),},// Opt-in support for SASS (using .scss or .sass extensions).// By default we support SASS Modules with the// extensions .module.scss or .module.sass{
test: sassRegex,
exclude: sassModuleRegex,
use:getStyleLoaders({
importLoaders:3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,},'sass-loader'),// Don't consider CSS imports dead code even if the// containing package claims to have no side effects.// Remove this when webpack adds a warning or an error for this.// See https://github.com/webpack/webpack/issues/6571
sideEffects:true,},// Adds support for CSS Modules, but using SASS// using the extension .module.scss or .module.sass{
test: sassModuleRegex,
use:getStyleLoaders({
importLoaders:3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules:{
getLocalIdent: getCSSModuleLocalIdent,},},'sass-loader'),},
把这段中关于Sass的配置复制下来,把关键字换成less(sass ==> less)
//less配置 可以直接复制上面的sass配置之后改成less就行{
test: lessRegex,
exclude: lessModuleRegex,
use:getStyleLoaders({
importLoaders:3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,},'less-loader'),// Don't consider CSS imports dead code even if the// containing package claims to have no side effects.// Remove this when webpack adds a warning or an error for this.// See https://github.com/webpack/webpack/issues/6571
sideEffects:true,},{
test: lessModuleRegex,
use:getStyleLoaders({
importLoaders:3,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules:{
getLocalIdent: getCSSModuleLocalIdent,},},'less-loader'),},