1 | var colors = require('colors');
|
2 | var svgo = require('svgo');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | module.exports = function (content) {
|
10 | if (!content) {
|
11 | return content;
|
12 | }
|
13 | var space;
|
14 | var match = content.match(/^[^\n\S]+/);
|
15 | if (match) {
|
16 | space = match[0];
|
17 | }
|
18 | else {
|
19 | space = '';
|
20 | }
|
21 |
|
22 | new svgo({
|
23 | plugins: [{
|
24 | cleanupIDs: {
|
25 | remove: false
|
26 | }
|
27 | }]
|
28 | }).optimize(content, function (svg) {
|
29 | if (svg.error) {
|
30 | console.error(colors.red(svg.error));
|
31 | return content;
|
32 | }
|
33 | content = svg.data;
|
34 | });
|
35 |
|
36 | return space + content;
|
37 | }; |
\ | No newline at end of file |