安装依赖
yarn add less less-loader --dev
yarn add less less-loader -D
配置 webpack
修改 webpack 的配置文件,一般是 webpack.config.js,增加 less 的支持
const lessRegex = /\.less$/;
const lessModuleRegex = /\.module\.less$/;
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: {
localIdentName: '[path][name]__[local]--[hash:base64:5]',
},
},
'less-loader'
),
},
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 3,
sourceMap: isEnvProduction && shouldUseSourceMap,
modules: {
getLocalIdent: getCSSModuleLocalIdent,
},
},
'less-loader'
),
},