解決antd icon打包過大的問題

1.webpack配置aliaswebpack

resolve: {
    alias: {
        ...
        '@ant-design/icons/lib/dist$': path.resolve(__dirname, '../src/icons.ts'),
        '@': path.resolve(__dirname, '../src')
    }
}

2.在src目錄下編寫icons.ts,內容是使用到的iconweb

export {default as UserOutline} from '@ant-design/icons/lib/outline/UserOutline';
export {default as CloseCircleFill} from '@ant-design/icons/lib/fill/CloseCircleFill';
export {default as InfoCircleFill} from '@ant-design/icons/lib/fill/InfoCircleFill';
export {default as CheckCircleFill} from '@ant-design/icons/lib/fill/CheckCircleFill';

注:1.若是打包錯誤,請檢查alias的配置和icons.ts的路徑
2.icon.ts的內容,包括本身用到的icon和組件用到的iconcode

相關文章
相關標籤/搜索