facebook / create-react-app

Set up a modern web app by running one command.

Home Page:https://create-react-app.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

0.8.0 breaks svg sprite

bogdansoare opened this issue · comments

The change in 0.8.0 to use url-loader with limit 10k as a default loader breaks my svg sprite system.

The svg sprite system works like this: I put all my svgs in one folder, run svg-sprite to generate svg sprite (which is below 10k), then I have a custom Icon component in which I import the svg sprite and load the apropriate icon using fragment identifiers

Icon Component:

import React, { PropTypes } from 'react'
import svgSprite from '../img/symbol/sprite.svg'

function Icon({ name }) {
  return (
    <svg>
      <use xlinkHref={`${svgSprite}#${name}`} />
    </svg>
  )
}

Any idea how to fix this besides just adding more svgs to the sprite until it is bigger than 10k?

commented

Do fragments break with base64 URLs?

commented

Or do you rather mean that it's unfortunate sprites get duplicated?

If this is the case I think we should disable inlining for SVG. After all the user could've put it directly into components if they wanted to inline it.

Fragments break with base64.
Also like you said it's unfortunate that we can't leverage caching and that we inline the whole sprite everywhere an icon is used.

Disabling inlining for SVG would solve the issue.
I'm going to research a bit svg sprite systems and see if there are other reasonable possibilities besides fragment identifiers.

commented

Would you like to make a PR for a special case for SVG?

Sure, I'll be glad to make a PR

commented

Fixed by #1180.

What is required to make inlining of svg images below 10k work (again)?

Is there a Option to re-activate base64 import for SVGs? I'm using SVGs in my CSS and i don't like the workflow of manually transforming it to base64 first.