- If you need to use material icons in your project for example.
- If you need to add cusom icons
File examples bellow
You will need to alias default icons path in a same way you would if addressing the bundle size issue
- install svgson
npm i -D svgson
- create
./src/icons.js
file in your project - Add the following to your webpack's
resolve
:
alias: {
'@ant-design/icons/lib/dist$': path.resolve(__dirname, '../src/icons.js')
}
- Create the fllowing file structure in the root of your project:
icons/
├── generate.js
└── svg
├── search.svg
└── wc.svg
- add npm script
"generate:icons": "node ./icons/generate.js"
to your package.json
Now place your icons in the svg directory
From cmd run npm run generate:icons
This will generate usable icons in ./icons/icons directory your file structure should now be like this:
icons/
├── generate.js
├── icons
│ ├── SearchOutline.js <-- generated
│ └── WcOutline.js <-- generated
└── svg
├── search.svg
└── wc.svg
You are now can export this generated icons in the file we aliased erlier in webpack (the icons.js) and use them as if this icons came from Antd
svg file name used as name of the icon
for example using button as the following will give you 'wc' icon on the button:
<Button icon="ws">Take me to the restroom</Button>
Using custom (not overwritten) icons won't work as <Icon type="ws" />
Fortunatly Antd <Icon/>
component provides a render prop so this will work <Icon component={ <WcIconComponnet/> } />
Icons name which are exists in Antd and being overwritten will work just fine.
So using <Icon type="search" />
, even if we performed override on it will work just fine as well.
Note that icons named with the same name as in Antd will override the originals. For example: search.svg exists in Antd so it will be overriten by yours, ws.svg is a custom one