electron-userland / electron-webpack

Scripts and configurations to compile Electron applications using webpack
https://webpack.electron.build/
906 stars 171 forks source link

Added the ability to import SVGs as a React Component #422

Closed veighthedev closed 3 years ago

veighthedev commented 3 years ago

Added svgr as a loader for SVGs which allows you to import SVGs as Components.

https://react-svgr.com/docs/webpack/

veighthedev commented 3 years ago

Update: Made it using the old url-loader options in addition to the SVG loader

loopmode commented 3 years ago

Do I understand correctly that with this change, the default behavior does not change for existing projects? And that only if you use the named import explicitly you'll have the new behavior?

veighthedev commented 3 years ago

@loopmode yeah, the svg can still be imported as a url string, like it was before.

Example:

import starUrl, { ReactComponent as Star } from './star.svg'

const App = () => (
  <div>
    <img src={starUrl} alt="star" />
    <Star />
  </div>
)