Skip to content

Instantly share code, notes, and snippets.

@el22or
Last active June 9, 2020 21:03
Show Gist options
  • Save el22or/2b3e12a5b0f07a5a83335b4b34dc5ed9 to your computer and use it in GitHub Desktop.
Save el22or/2b3e12a5b0f07a5a83335b4b34dc5ed9 to your computer and use it in GitHub Desktop.
multipass: true
plugins:
- addAttributesToSVGElement: false
- addClassesToSVGElement: false
- cleanupAttrs: true
- cleanupEnableBackground: true
- cleanupIDs: true
- cleanupListOfValues: true
- cleanupNumericValues:
floatPrecision: 2
- collapseGroups: true
- convertColors: true
- convertPathData: true
- convertShapeToPath: true
- convertStyleToAttrs: true
- convertTransform: true
- mergePaths: true
- minifyStyles: true
- moveElemsAttrsToGroup: true
- moveGroupAttrsToElems: true
- removeAttrs: true
- removeComments: true
- removeDesc: true
- removeDimensions: true
- removeDoctype: true
- removeEditorsNSData: true
- removeElementsByAttr: true
- removeEmptyAttrs: true
- removeEmptyContainers: true
- removeEmptyText: true
- removeHiddenElems: true
- removeMetadata: true
- removeNonInheritableGroupAttrs: true
- removeRasterImages: true
- removeStyleElement: true
- removeTitle: true
- removeUnknownsAndDefaults: true
- removeUnusedNS: true
- removeUselessDefs: true
- removeUselessStrokeAndFill: true
- removeViewBox: true
- removeXMLNS: false
- removeXMLProcInst: true
- sortAttrs: true
- transformsWithOnePath: true
js2svg:
pretty: true
indent: ' '

SVG Tool

Install svg2sprite CLI (global)

npm i -g svg2sprite-cli

Install other packages

npm install

Use

  1. npm run svgo
  2. npm run svg2sprite

Explain folder structure

./src/assets/images/
  ./icons-src/
  ./icons-optimized/
  ./symbol-defs.svg
./.svgo.yml
./package.json

{
"name": "svg-tool",
"scripts": {
"svg2sprite": "svg2sprite ./src/assets/images/icons-optimized/ ./src/assets/images/symbol-defs.svg",
"svgo": "./node_modules/svgo/bin/svgo -f ./src/assets/images/icons-src -o ./src/assets/images/icons-optimized --config .svgo.yml"
},
"devDependencies": {
"svg2sprite-cli": "^2.0.1",
"svgo": "^1.3.0"
}
}
<div>
<svg>
<use [attr.xlink:href]="'assets/images/symbol-defs.svg#' + 'icon-file-name-without-extension'" style="fill: currentColor;"></use>
</svg>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment