antd-iconfont
antd离线字体
要解决的问题
- antd默认iconfont指向的是阿里在公网CDN上部署的url
- 项目需要在本地进行部署,特别是打包在Electron中运行的时候,使用的是本地文件的访问方式,希望能离线使用
在create-react-app中的配置方法
- 安装依赖
$ yarn add antd-iconfont$ yarn add babel-plugin-import -D$ yarn add less less-loader -D
- 配置babel插件
// 注意style要设置成true,使用less而非css
- 配置webpack.xxx.config.js
// module => rules中增加项// 通过修改modifyVars中的值修改默认antd.less的默认参数 test: /\.less$/ use: require loader: require options: importLoaders: 1 loader: require options: ident: 'postcss' // https://webpack.js.org/guides/migrating/#complex-options loader: require options: modifyVars: '@icon-url': '"~antd-iconfont/iconfont"'