New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-svgstore

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-svgstore

Combine svg files into one with <symbol> elements

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
34K
increased by0.85%
Maintainers
1
Weekly downloads
 
Created
Source

gulp-svgstore

Build Status

Combine svg files into one with <symbol> elements. Read more about this in CSS Tricks article.

If you need similar plugin for grunt, I encourage you to check grunt-svgstore.

Caution:

This is still incomplete and api may be changed anytime. I plan to add tests and then freeze api.

Options:

  • fileName — the name of result file
  • prefix — prefix for ids of the elements
  • inlineSvg — output only <svg> element without <?xml ?> and DOCTYPE to use inline
  • emptyFills - remove all fill="none" so they can be changed in css
  • transformSvg(svg, cb) — should modify svg libxmljs element and call cb(err) when done

Usage

The following script will combine circle.svg and square.svg into single svg file with <symbol> elements.

var svgstore = require('gulp-svgstore')
var gulp = require('gulp')
var svgmin = require('gulp-svgmin')
gulp.task('default', function () {
  return gulp.src('test/fixtures/*.svg')
             .pipe(svgmin())
             .pipe(svgstore({ fileName: 'icons.svg'
                            , prefix: 'icon-'
                            , inlineSvg: false
                            }))
             .pipe(gulp.dest('test/'))
})

Combined svg:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="icon-circle" viewBox="0 0 40 40">
    <circle fill="#fff" stroke="#1D1D1B" stroke-miterlimit="10" cx="20" cy="20" r="10"/>
  </symbol>
  <symbol id="icon-square" viewBox="0 0 40 40">
    <path stroke="#1D1D1B" stroke-miterlimit="10" d="M10 10h20v20h-20z"/>
  </symbol>
</svg>

Transform result svg

Add display:none

To add style="display:none" use the following transformSvg function:

function transformSvg (svg, cb) {
  svg.attr({ style: 'display:none' })
  cb(null)
}

Remove all fills

To remove all fill attributes use the following transformSvg function:

function transformSvg (svg, cb) {
  svg.find('//*[@fill]').forEach(function (child) {
    child.attr('fill').remove()
  })
  cb(null)
}

Keywords

FAQs

Package last updated on 11 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc