https://blog.csdn.net/xxygreen_hand/article/details/90672774(全配置Less和antd主题)
在学习一些react项目时,视频教程中的webpack版本较低,在我们使用npm run eject 或者yarn eject来暴露配置文件时,
发现在config下没有webpack.config.dev.js和webpack.config.prods.js文件,只有一个webpack.config.js文件。此时要配置less(因为antD是使用less),如下
在webpack.config.js下 配置完之后要重启生效
https://blog.csdn.net/czkcui123/article/details/89515949
-
//找到此位置
-
// style files regexes
-
const cssRegex = /.css$/;
-
const cssModuleRegex = /.module.css$/;
-
const sassRegex = /.(scss|sass)$/;
-
const sassModuleRegex = /.module.(scss|sass)$/;
-
-
//在此添加如下两个常量
-
const lessRegex =/.less$/;
-
const lessModuleRegex=/.module.less$/;
-
//找到此位置
-
{
-
test: cssRegex,
-
exclude: cssModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 1,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
// 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 (https://github.com/css-modules/css-modules)
-
// using the extension .module.css
-
{
-
test: cssModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 1,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
modules: true,
-
getLocalIdent: getCSSModuleLocalIdent,
-
}),
-
},
-
-
//在这之后仿照上面添加如下代码
-
{
-
test: lessRegex,
-
exclude: lessModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 2,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
sideEffects: true,
-
},
-
{
-
test: lessModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 2,
-
modules: true,
-
getLocalIdent: getCSSModuleLocalIdent,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
},
-
//找到此位置
-
// style files regexes
-
const cssRegex = /.css$/;
-
const cssModuleRegex = /.module.css$/;
-
const sassRegex = /.(scss|sass)$/;
-
const sassModuleRegex = /.module.(scss|sass)$/;
-
-
//在此添加如下两个常量
-
const lessRegex =/.less$/;
-
const lessModuleRegex=/.module.less$/;
-
-
// This is the production and development configuration.
-
// It is focused on developer experience, fast rebuilds, and a minimal bundle.
-
//找到此位置
-
{
-
test: cssRegex,
-
exclude: cssModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 1,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
// 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 (https://github.com/css-modules/css-modules)
-
// using the extension .module.css
-
{
-
test: cssModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 1,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
modules: true,
-
getLocalIdent: getCSSModuleLocalIdent,
-
}),
-
},
-
-
//在这之后仿照上面添加如下代码
-
{
-
test: lessRegex,
-
exclude: lessModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 2,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
sideEffects: true,
-
},
-
{
-
test: lessModuleRegex,
-
use: getStyleLoaders({
-
importLoaders: 2,
-
modules: true,
-
getLocalIdent: getCSSModuleLocalIdent,
-
sourceMap: isEnvProduction && shouldUseSourceMap,
-
}),
-
},