PostCSS plugin that maps over each `url` property in a declaration
npm install postcss-map-urlPorted from rework-plugin-url
[PostCSS] plugin that maps over each url property in a declaration.
``console`
$ npm install postcss-map-url --save-dev
Takes a callback function that recieves the url
`js
var fs = require('fs');
var postcss = require('postcss');
var mapUrl = require('postcss-map-url');
var css = fs.readFileSync('input.css', 'utf8');
var output = postcss()
.use(mapUrl(myMapFunc))
.process(css)
.css;
// Your map function that takes the url as a parameter and
// should return a modified url
function myMapFunc(url) {
return 'http://example.com' + url;
}
`
Input
` css`
body {
background: url(/images/bg.png);
}
Output
` css``
body {
background: url(http://example.com/images/bg.png);
}
See [PostCSS] docs for examples for your environment.
[PostCSS]: https://github.com/postcss/postcss