Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attributes like "stroke" or "fill" on the <svg> tag are missing in the sprite #141

Closed
a-neumann opened this issue Jun 22, 2017 · 2 comments
Assignees
Labels

Comments

@a-neumann
Copy link

a-neumann commented Jun 22, 2017

Do you want to request a feature, report a bug or ask a question?
Bug report

What is the current behavior?
The symbols I import don't look like they should. They have no stroke like in the preview but a black fill after loaded with svg-sprite-loader.

Only the children of the <svg> element are extracted into the sprite.
Imported icons that have styling attributes like fill or stroke directly on the <svg> element were extraced to the sprite without these attributes.

What is the expected behavior?
Styling attributes that came from svg tags should be kept in the symbols inside the sprite.

If the current behavior is a bug, please provide the steps to reproduce, at least part of webpack config with loader configuration and piece of your code.
The best way is to create repo with minimal setup to demonstrate a problem (package.json, webpack config and your code).
It you don't want to create a repository - create a gist with multiple files

  • I was importing an icon set called feather-1.1.0 to my repository
  • I used the webpack loader to Import the Icons in my JS code like that:
import anchor from "../../icons/feather-1.1.0/anchor.svg";
// using react here
const test = (
    <svg viewBox={anchor.viewBox} style={{ width: "20px", height: "20px" }}>
        <use xlinkHref={anchor.url} />
     </svg>
);

Here is my webpack config:

{
    test: /\.svg$/,
    loader: "svg-sprite-loader",
    options: {
        extract: true,
        spriteFilename: "[chunkname]_icons.[hash:20].svg"
    }
}
...
plugins: [
    new SvgSpritePlugin(),

If this is a feature request, what is motivation or use case for changing the behavior?

Please tell us about your environment:

  • Node.js version: v6.9.2
  • webpack version: 3.0.0
  • svg-sprite-loader version: 3.0.5
  • OS type & version: Windows 10

Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

anchor.svg (original icon)

<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  <circle cx="12" cy="5" r="3"/>
  <line x1="12" y1="22" x2="12" y2="8"/>
  <path d="M5,12H2a10,10,0,0,0,20,0H19"/>
</svg>

extracted sprite:

<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><style>
    .sprite-symbol-usage {display: none;}
    .sprite-symbol-usage:target {display: inline;}
  </style><symbol viewBox="0 0 24 24" id="anchor">
  <circle cx="12" cy="5" r="3" />
  <line x1="12" y1="22" x2="12" y2="8" />
  <path d="M5,12H2a10,10,0,0,0,20,0H19" />
</symbol></defs><use id="anchor-usage" xlink:href="#anchor" class="sprite-symbol-usage" /></svg>
@kisenka kisenka self-assigned this Jul 10, 2017
@kisenka kisenka added the bug label Jul 10, 2017
@billhannah
Copy link

This could be solved if we could configure the svgo options instead of just using the defaults

@kisenka
Copy link
Contributor

kisenka commented Aug 20, 2017

Shipped with svg-sprite-loader@3.2.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants