jhamlet / svg-react-loader

Webpack SVG to React Component Loader
MIT License
559 stars 82 forks source link

Is "import all in path" possible? #97

Open romanr opened 6 years ago

romanr commented 6 years ago

Usually all icons are stored in same folder. And it's a lot of code to specify each icon separately.

Rather than having tens of these lines:

import Icon1 from '/icons/Icon1.svg';
import Icon2 from '/icons/Icon2.svg';
import Icon3 from '/icons/Icon3.svg';

Is it possible to do something like this?

import icon* from '/icons/';

So you just drop images in that folder and they are ready to use.

If that's not possible, maybe have array of image names and import them?

like:

icons['Icon1.svg','icon2.svg','icon3.svg'];
import icons;

If not, is there any way to simplify an avoid having all that import code for each image?

varqasim commented 5 years ago

A suggestion would be maybe create a new file that you import all your SVGs and then export them all, so then in your component you just import the icons like so

{ myIcon1, myIcon2, myIcon3 } from "./icons"