自定义icon组件
import { createFromIconfontCN } from '@ant-design/icons'
const AtIcon = createFromIconfontCN({
scriptUrl: '/icons/font_test/iconfont.js'
})
export default AtIcon
使用组件时,报 GET http://localhost:3100/icons/font_test/iconfont.js net::ERR_ABORTED 404 (Not Found),说明 iconfont.js 没有加载成功,找不到。
项目使用的是webpack5,发现开发环境的配置项
devServer: {
static: {
directory: path.join(__dirname, '..', 'dist')
},
}
静态资源目录指向了dist目录,改成public,图标文件放在public下,就成功了