parsley/config/webpack/loaders/svg_loader.js
2018-09-09 16:37:25 -05:00

27 lines
715 B
JavaScript

module.exports = function(content) {
this.cacheable && this.cacheable();
var match = content.match(/<svg([^>]+)+>([\s\S]+)<\/svg>/i);
var attrs = {};
if (match) {
attrs = match[1];
if (attrs) {
attrs = attrs.match(/([\w-:]+)(=)?("[^<>"]*"|'[^<>']*'|[\w-:]+)/g)
.reduce(function(obj, attr){
var split = attr.split('=');
var name = split[0];
var value = true;
if (split && split[1]) {
value = split[1].replace(/['"]/g, '');
}
obj[name] = value;
return obj;
}, {})
}
content = match[2] || '';
};
return "module.exports = " + JSON.stringify({attributes: attrs, content: content});
};