yarn add less less-loader -D yarn eject
在webpack.config.js文件中css
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'错误webpack
//更新到最新版本就能够了 npm install -D babel-loader @babel/core @babel/preset-env webpack
////////////////////////////////////////////............................................................................................................................................................................../////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////############################################################################################################################################################################################################################################################web