Stas Gavrylov

@stasgavrylov

Lead Frontend Engineer @ Rails Reactor

Seamless SVG workflow
in
create-react-app

without
eject
ing

Problem

pencil.svg

Solutions

Option 0: <img> tag

Solutions

Option 1: Duplicate files

Solutions

Option 2: Inline SVGs

Solutions

Option 3: Icon Font

Solutions

Option 4:

"npm run eject" + some-svg-loader

Solutions

Option 5: SVG Sprites

svg-sprite
+
svg4everybody
+
<use>

svg-sprite
  1. Supports different outputs, uses SVGO, highly configurable
  2. File names will become IDs
  3. Remove FILL and STROKE attributes from SVGs in advance
svg4everybody

Adds external SVG support for all browsers

<use> element

Simplest use case

<SVGIcon /> (code)
SvgIcon.css
App.js

Links

Seamless SVG workflow

By Stas Gavrylov

Seamless SVG workflow

Using SVG sprites in single page apps

  • 716