先交代下背景
antd 按需加载,在package.json中配置babel
"babel": {
"presets": [
"react-app"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"libraryDirectory": "es",
"style": "css"
}
]
]
}
“antd”: “^3.19.4”,
“less”: “^3.10.3”,
“babel-plugin-import”: “^1.12.0”,
“less-loader”: “^5.0.0”,
现在项目需要自定义主题
- 首先修改package.json中babel配置, style 改为 true,并且去掉 libraryDirectory
"babel": {
"presets": [
"react-app"
],
"plugins": [
[
"import",
{
"libraryName": "antd",
"style": true
}
]
]
}
- 然后找config/webpack.config.js文件,搜一下 plugins,然后在这里加上这行代码
["import", {"libraryName": "antd", "libraryDirectory":"es", "style": true}],
- 最后加上loader