postcss-simple-svg
PostCSS plug-in which to insert inline SVG to CSS and allows you to manage it colors. Examples here
Features:
- Easy insert inline SVG to CSS
- Manage colors of your SVG image without editinig it
- Symbols sprites support
- Compression with svgo
- Support Evil Icons from box
Installation
npm install postcss-simple-svg --save-dev
Usage
PostCSS:
//...var postcss = ;var postcssSVG = ;var processors = //... , ;; ;
Gulp:
var gulp = ;var postcss = ; gulp;
Using this input.css
:
you will get:
Options
paths
Type: Array
Default: ['svg']
Example: ['pathToSVGDir1', 'pathToSVGDir2']
Required: false
You can define relative path to folders with SVG files.
func
Type: String
Default: 'svg' Example: 'url' Required: false
You can set func option to 'url' to support fallback to url("*.svg") links.
svgo
Type: Boolean
, Object
Default: false
Example: true
Required: false
You can set custom config for svgo module. Recommend to set true only for production build.
defaults
Type: String
Default: ''
Example: '[fill]: #00F800; .glass[fill]: rgba(0, 0, 255, 0.1);'
Required: false
You can set default rules for all included SVG
ei
Type: Boolean
, Object
Default: true
Example: { "dfaults": "[fill]: red" }
Required: false
You can set false to disable initializing Evil Icons. Or you can set different defaults only for Evil Icons.
debug
Type: Boolean
Default: false
Required: false
You can set false to disable initializing Evil Icons. Or you can set different defaults only for Evil Icons.
silent
Type: Boolean
Default: true
Required: false
Do not throw errors
Colors API
You can replace only existing values of fill
and stroke
attributes.
To replace colors you can use simple selectors.
You can use several selectors for one SVG.
In the bottom you can see this selectors in ascending order.
For better understanding of selectors check examples.
Selectors:
[color]
All fill
and stroke
attributes
[fill]|[stroke]
All fill
or stroke
attributes
tagName[fill]|tagName[stroke]
fill
or stroke
tag attributes with name tagName
.className[fill]|.className[stroke]
fill
or stroke
tag attributes with class className
colorGroupN
All colors in SVG are grouped in color groups. N - group index, starts from 0 (from the top of SVG document)
#identifier[fill]|#identifier[stroke]
fill
or stroke
tag attributes with id identifier
colorN
All colors in SVG have index. N - index, starts from 0 (from the top of SVG document)
Contributing
Pull requests are welcome. To run development envirement
git clone git@github.com:taunoha/postcss-simple-svg.git
cd postcss-simple-svg
npm install
gulp watch