Skip to content

Instantly share code, notes, and snippets.

@axe312ger
Last active June 16, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axe312ger/c79552cacfe42c679f5ca554f5444172 to your computer and use it in GitHub Desktop.
Save axe312ger/c79552cacfe42c679f5ca554f5444172 to your computer and use it in GitHub Desktop.
Created optimized svg sprite which allows coloring via css by using currentColor. Uses svgo and svgSprite.
multipass: true
js2svg:
pretty: true
indent: 2
plugins:
- convertColors:
currentColor: true
- collapseGroups: true
- convertShapeToPath: true
- mergePaths: true
- transformsWithOnePath: true
- convertPathData: true
- convertTransform: true
- removeRasterImages: true
- cleanupListOfValues: true
- removeUselessStrokeAndFill: true
- removeUnusedNS: true
- cleanupNumericValues: true
- removeUnknownsAndDefaults: true
- removeNonInheritableGroupAttrs: true
- convertStyleToAttrs: true
- cleanupAttrs: true
- removeDoctype: true
- removeXMLProcInst: true
- removeComments: true
- removeMetadata: true
- removeTitle: true
- removeDesc: true
$ svgo --pretty --config=./.svgo.yml images/icons-original images/icons

The pretty is ofc optional

In case you want to continue with svgSprite to generate icon stacks:

svgSprite({
  mode: {
    symbol: {
      dest  : 'sprites',
      sprite: 'icons.svg',
      inline: true,
      example: true,
      render: {
        scss: true
      }
    },
  }
})

or in case you want to do all by one, this is also possible. We wanted to store the optimized images separately, thats why we split this up.

svgSprite({
  mode: {
    symbol: {
      dest  : 'sprites',
      sprite: 'icons.svg',
      inline: true,
      example: true,
      render: {
        scss: true
      }
    },
  },
  shape: {
    transform: [
      {
        svgo: {
          plugins: [
            {
              convertColors: {
                currentColor: true
              }
            },
            { collapseGroups: true },
            { convertShapeToPath: true },
            { mergePaths: true },
            { transformsWithOnePath: true },
            { convertPathData: true },
            { convertTransform: true },
            { removeRasterImages: true },
            { cleanupListOfValues: true },
            { removeUselessStrokeAndFill: true },
            { removeUnusedNS: true },
            { cleanupNumericValues: true },
            { removeUnknownsAndDefaults: true },
            { removeNonInheritableGroupAttrs: true },
            { convertStyleToAttrs: true },
            { cleanupAttrs: true },
            { removeDoctype: true },
            { removeXMLProcInst: true },
            { removeComments: true },
            { removeMetadata: true },
            { removeTitle: true },
            { removeDesc: true }
          ]
        }
      }
    ]
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment