postcss-svg-fallback
1.5.0 • Public • Published svg-fallback
An automatic SVG converter for your CSS files, built on top of the PostCSS ecosystem.
Usage
Right now it is only possible to use this as a PostCSS plugin:
var postcss = require('postcss')
var svgFallback = require('postcss-svg-fallback')
var input = read();
postcss()
.use(svgFallback({
basePath: '',
dest: '',
fallbackSelector: '.no-svg',
disableConvert: false,
})
.process(input)
.then(function(processor) {
var output = processor.toString();
});
Note: we must use the async version of postcss
Converts this:
.icon {
background: url(images/sun-is-shining.svg) no-repeat;
background-size: 20px 20px;
}
.icon-inline {
background: url(data:image/svg+xml; .. svg data ..) no-repeat;
background-size: 20px 20px;
}
to this:
.icon {
background: url(images/sun-is-shining.svg) no-repeat;
background-size: 20px 20px;
}
.no-svg .icon {
background-image: url(images/sun-is-shining-20x20.png);
}
.icon-inline {
background: url(data:image/svg+xml; .. svg data ..) no-repeat;
background-size: 20px 20px;
}
.no-svg .icon-inline {
background-image: url(3547c094eaf671040650cdcab2ca70fd-20x20.png);
}
Converting is done with PhantomJS and is only done for images that actually need conversion (background-size
& mtime
).
Package Sidebar
Install
npm i postcss-svg-fallback
Weekly Downloads