create-react-app 最新版本安装less
1.暴露webpack配置文件
npm run ejectyarn run eject复制代码2. 安装 less less-lorder
npm install less less-loaderyarn add less less-loader复制代码3.找到config文件夹中的webpack.config.js配置文件 添加相应less规则 复制上面的规格改成less就好
{ test: lessRegex, exclude: lessModuleRegex, use: getStyleLoaders( { importLoaders: 2, sourceMap: isEnvProduction && shouldUseSourceMap, }, 'less-loader' ), sideEffects: true, }, { test: lessModuleRegex, use: getStyleLoaders( { importLoaders: 2, sourceMap: isEnvProduction && shouldUseSourceMap, modules: true, getLocalIdent: getCSSModuleLocalIdent, }, 'less-loader' ), }复制代码
将这段代码添加到module中的rules数组里就OK了