执行npm run eject 暴露模块 安装 npm i less less-loader -D 1.打开 react app 的 webpack.config.js const sassRegex = /\.(scss|sass)$/; const sassModuleRegex = /\.module\.(scss|sass)$/; //添加 const lessRegex = /\.less$/; const les
执行npm run eject 暴露模块
安装 npm i less less-loader -D
1.打开 react app 的 webpack.config.js
const sassRegex = /\.(scss|sass)$/; const sassModuleRegex = /\.module\.(scss|sass)$/; //添加const lessRegex = /\.less$/; const lessModuleRegex = /\.module\.less$/; 2. 在 大概467 行 添加 { test: lessRegex, exclude: sassModuleRegex, 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 sideEffects: true, }, // Adds support for CSS Modules, but using SASS // using the extension .module.scss or .module.sass { test: lessModuleRegex, use: getStyleLoaders( { importLoaders: 2, sourceMap: isEnvProduction && shouldUseSourceMap, modules: true, getLocalIdent: getCSSModuleLocalIdent, }, ‘less-loader‘ ), }, # 必须在 file-loader 上面 这时 会发现 npm start 会报错 删除 node_modules 重新安装 npm instal 再npm tsatrt 成功 鼓掌