javascript – How to make Vite add react-icons to a separate .js file when executing ‘npm run dev’?

I have to show icons (100+) in my React app so the used can select one which will be used on some diagram.

I was able to achieve that so my import looks like

...
import * as IconsFa from 'react-icons/fa'
import * as IconsIo from 'react-icons/io'
import * as IconsSi from 'react-icons/si'
import * as IconsTb from 'react-icons/tb'
import * as IconsDi from 'react-icons/di'
...

My problem is that Vite will create one big JS file (when executing npm run build) which includes react-icons library.
I should use lazy import but as I know it is not possible when using star in import. Because I want to show lots of icons so I can’t just enlist them one by one.

What can be done to create a separate .js file for react-icons during the build?

Read more here: Source link