Create React App 安裝less 報錯

執行npm run eject 暴露模塊css

 

安裝 npm i  less less-loader -Dnode

 

1.打開 react app 的 webpack.config.js react

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 
成功 
 
 
鼓掌
相關文章
相關標籤/搜索