2

I'm trying to use https://github.com/kisenka/svg-sprite-loader this package for using svg icons in my app.

Eventually it worked, but I have to import every icon: import up from '@/assets/svg/up.svg'

How can I do it once, auto-importing all icons from my svg folder?

Victor
  • 5,073
  • 15
  • 68
  • 120
  • linked - [How to inline multiple SVGs with React using Webpack?](https://stackoverflow.com/q/38353987/104380) – vsync Jun 19 '19 at 14:51

1 Answers1

1

Prepare a module like sprites.js with the following (adjust your path to svgs):

require.context('path/to/your/svg/folder', true, /\.svg$/);

And include it in your entry point.

More information about require.context in the official Webpack docs

Alex Ljamin
  • 737
  • 8
  • 31
Greg
  • 783
  • 4
  • 11
  • [`require.context`](https://stackoverflow.com/a/54066904/104380) is webpack-specific. worth mentioning. – vsync Jun 19 '19 at 12:10