首先引入less less-loader
cnpm install less less-loader -D
接着使用npm run eject 暴露webpack的配置文件,在config里面找到webpack.base.js文件。
先引入判断less正则
const lessRegex = /\.less$/;
const lessModuleRegex = /\.module\.less$/;
配置loader
{
test: lessRegex,
exclude: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction && shouldUseSourceMap,
},
'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