ant design 4.x 實(shí)現(xiàn)按需加載:
1. 安裝按需加載插件:
? yarn add babel-plugin-import
2.然后在craco.config,.js里加上
babel: {
? ? plugins: [
? ? ? ? [
? ? ? ? "import",
? ? ? ? {
? ? ? ? ? "libraryName": "antd",
? ? ? ? ? "libraryDirectory": "es",
? ? ? ? ? "style": true //設(shè)置為true即是less
? ? ? ? ? }
? ? ? ]
? ? ]
},
3.然后在src/App.less中去除樣式引入棉胀,按需加載之后只需引入組件即可法瑟,無(wú)需在額外引入樣式文件,babel會(huì)自動(dòng)按需幫你完成樣式的引入唁奢。