Skip to content

Releases: svg/svgo-components

v0.4.0

11 Nov 18:42
Compare
Choose a tag to compare
  • upgraded to SVGO v3
  • added types support
  • added "after" hook for index generation

v0.3.1

25 Dec 10:14
Compare
Choose a tag to compare
  • fixed passing svgProps to root element other than "svg" (#7)
  • fixed rendering text and cdata nodes (3e1189c)

Thanks to @jeetiss and @TrySound

v0.3.0

20 Dec 10:47
Compare
Choose a tag to compare

This is a big release. We added custom targets support and react-native-svg target

Generating import

Templates get components field in options with the list of capitalized tags to generate import

`
import {${components.join(', ')}} from 'react-native-svg'
`

Custom target

Target option now accepts custom value which prevents tags and attributes from transforming (for example clip-path -> clipPath). This allows to pass own SVGO plugin with transformation for your own renderer.

const yourFrameworkTargetPlugin = {
  type: "visitor",
  name: "svgo-jsx-your-framework",
  fn: () => {
    const yourFrameworkTags = {
      svg: "Svg"
    }
    const yourFrameworkAttributes = {
      "xlink:href": "xlinkHref"
    }
    return {
      element: {
        enter: (node) => {
          node.name = yourFrameworkTags[node.name] ?? node.name;
          // attributes recreation is used to preserve order
          const newAttributes = {};
          for (const [name, value] of Object.entries(node.attributes)) {
            newAttributes[yourFrameworkAttributes[name] ?? name] = value;
          }
          node.attributes = newAttributes;
        },
      },
    };
  },
};

export const config = {
  ...
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          removeViewBox: false,
        },
      },
    },
    { name: "removeXMLNS" },
    { name: "prefixIds" },
    yourFrameworkTargetPlugin
  ]
};

React-native-svg

Based on features above we built support for react-native via react-native-svg package.

export const config = {
  target: 'react-native-svg'
}

Template customization is simple enough

`// Generated from ${sourceFile}

import {${components.join(", ")}} from 'react-native-svg'

export const ${componentName} = (props) => {
  return (
    ${jsx}
  );
}
`

Thanks to @jeetiss for suggestion and review!

v0.2.5

16 Nov 22:11
Compare
Choose a tag to compare

Fixed published files broken by npm

v0.2.1

29 Oct 22:29
Compare
Choose a tag to compare

In this release was added shebang to cli. This fixes running it in linux. See #1

Thanks to @renatorib!

v0.2.0

30 Aug 11:40
Compare
Choose a tag to compare

In this release we upgraded SVGO to use the new preset-default plugin instead of deprecated extendDefaultPlugins utility.
Icons are now optimized even more with removed "xmlns" attribute not necessary in svg inlined into html.