webpack-contrib / svg-inline-loader

Inline SVG loader with cleaning-up functionality

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an option "auto add class name from svg file name".

liamwang opened this issue · comments

Automatically add class name to <svg> tag from its svg file name.

What does the proposed API look like?

A file named logo.svg :

<svg class="foo" viewBox="0 0 25 25">
    <path d="..."/>
</svg>

The options :

  {
    test: /\.svg$/,
    loader: 'svg-inline-loader',
    options: {
      className: 'icon-[filename]',
      // or
      // classPrefix: 'icon-',
      // autoClassName: true
    }
  }

The expected output result :

<svg class="icon-logo" viewBox="0 0 25 25"><path d="..."/></svg>

Would be handy indeed. Now I have to manually add classnames to make sure I have certain styling adapted (like coloring fills).

Would an option to add a custom class (from string or file name) be accepted? I can look into doing this, but there are a bunch of PRs hanging around as it is...

commented

Has anybody found an alternative way of doing this?