question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for SVG in CSS files

See original GitHub issue

This is a great loader, but it shouldn’t break when the svg file is loaded by an scss file. As in this example:

.foo {
   background-image: url(images/icon.svg);
}

Currently, these images are loaded as [object Object] strings.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:19
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

22reactions
P0lipcommented, Jan 9, 2018

There is a very clean way to achieve it. Just use the issuer field, which should be equal to file that initiated the import.

// In your webpack config
{
  test: /\.svg$/,
  issuer: /\.jsx?$/,
  use: [
    {
      loader: "babel-loader"
    },
    {
      loader: "react-svg-loader",
      options: {
        jsx: true // true outputs JSX tags
      }
    }
  ]
}

If you have any other loaders (like file-loader etc.) matching /\.svg$/ pattern, you may need to apply that rule for them as well, i.e. issuer: /\.s?css$/,

5reactions
andersaloofcommented, May 15, 2017

Could also be fixed by separating SVG files used in JS and CSS into two different folders, and adjust the webpack config to only use react-svg-loader on SVG files in one of the folders…

test: /.svg-js(.*)\.svg$/,
Read more comments on GitHub >

github_iconTop Results From Across the Web

SVG Properties and CSS
SVG has its own set of elements, attributes and properties to the extent that inline SVG code can get long and complex. By...
Read more >
SVG and CSS - SVG: Scalable Vector Graphics | MDN
This page illustrates the application of CSS to the specialized language for creating graphics: SVG.
Read more >
"svg" | Can I use... Support tables for HTML5, CSS3, etc
3 IE9-11 & Edge don't properly scale SVG files. Adding height, width, viewBox, and CSS rules seems to be the best workaround.
Read more >
How to style SVG with external CSS? - Stack Overflow
If you want to keep your SVG in files, the CSS needs to be defined inside of the SVG file. You can do...
Read more >
How to Use SVG Images in CSS and HTML – A Tutorial for ...
SVG stands for Scalable Vector Graphics. It is a unique type of image format for vector-based graphics written in Extensible Markup Language ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found