Create React App 安装less 报错

执行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 
成功 
 
 
鼓掌

 

posted @ 2019-07-27 15:24  \面朝阳光/  阅读(335)  评论(0编辑  收藏  举报