Since I could not find an established way to do this, I had to solve it myself. I wrote a simple node module that wraps stylus.url() , but replaces it as inline SVGs.
Link to the module: https://www.npmjs.com/package/stylus-inline-svg
With the exception of some checks, he basically does this:
found = stylus.utils.lookup(url.string, options.paths); if(!found) return literal; buf = fs.readFileSync(found); buf = String(buf) .replace(/<\?xml(.+?)\?>/, '') .replace(/^\s+|\s+$/g, '') .replace(/(\r\n|\n|\r)/gm, ''); return new stylus.nodes.Literal("url('data:image/svg+xml;utf8," + buf + "')");
source share