首先安装less语言所需要的相关依赖
npm i less less-loader --save
然后打开项目中 config/webpack.config.js 一共修改了三处
//添加less配置
const lessRegex = /\.less$/;
const lessModuleRegex = /\.module\.less$/;
// 参数lessOptions为添加项
const getStyleLoaders = (cssOptions, lessOptions, preProcessor) => {
const loaders = [
isEnvDevelopment && require.resolve('style-loader'),
isEnvProduction && {
loader: MiniCssExtractPlugin.loader,
options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
},
{
loader: require.resolve('css-loader'),
options: cssOptions,
},
// 添加 Less 配置
{
loader: require.resolve('less-loader'),
options: lessOptions,
},
{
// Options for PostCSS as we reference these option