Skip to content

Commit cbed5a8

Browse files
committed
Added options to SVGO to prevent stripping og stroke and fill attributes
1 parent d8e0ac8 commit cbed5a8

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

index.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ var templates = ['all', 'svg', 'icon'],
1212

1313
var settings = {
1414
babel: {},
15-
svgo : {}
15+
svgo : {
16+
plugins: [
17+
{
18+
removeViewBox: false
19+
}, {
20+
removeUselessStrokeAndFill: false
21+
}
22+
]
23+
}
1624
};
1725

1826
var isSVG = function (filename) {
@@ -42,12 +50,10 @@ var type = 'svg',
4250
var transform = function (filename) {
4351

4452
var write = function (buffer) {
45-
4653
data += buffer;
4754
};
4855

4956
var end = function () {
50-
5157
svgo.optimize(data, out);
5258
};
5359

@@ -56,6 +62,14 @@ var transform = function (filename) {
5662
var source = render(filename, svg.data),
5763
output = babel.transform(source, settings.babel);
5864

65+
var replaceAttribute = function (a, str) {
66+
return str.replace(/-(.)/g, function (_, letter) {
67+
return letter.toUpperCase();
68+
});
69+
};
70+
71+
output.code = output.code.replace(/\"(clip-path|fill-opacity|font-family|font-size|marker-end|marker-mid|marker-start|stop-color|stop-opacity|stroke-width|stroke-linecap|stroke-dasharray|stroke-opacity|text-anchor)\"/g, replaceAttribute);
72+
5973
stream.queue(output.code);
6074
stream.queue(null);
6175
};

0 commit comments

Comments
 (0)