-
npm run eject
暴露wepack.config.js
配置
-
npm i less less-loader --save
下载less
和less-loader
- 仿照
create-react-app
配置sass
代码配置less.
const lessRegex = /\.less$/
const lessModuleRegex = /\.module\.less$/
oneOf:[
...,
{
test: lessRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
},
'less-loader'
)
},
{
test: lessModuleRegex,
use: getStyleLoaders(
{
importLoaders: 2,
sourceMap: isEnvProduction
? shouldUseSourceMap
: isEnvDevelopment,
modules: true,
getLocalIdent: getCSSModuleLocalIdent
},
'less-loader'
),
sideEffects: true
},Ï
]
- 使用css-module的less文件加上.module,如
index.module.less
- 使用时注意
import styles from './index.module.less'
<div className={styles.xx}></div>
样式名不能加中线