forked from nextapps-de/spotlight
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsvgo.js
59 lines (50 loc) · 1.42 KB
/
svgo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const fs = require('fs');
const path = require('path');
let { optimize } = require('svgo');
const plugins = [
'cleanupAttrs',
'removeDoctype',
'removeXMLProcInst',
'removeComments',
'removeMetadata',
'removeTitle',
'removeDesc',
'removeUselessDefs',
'removeEditorsNSData',
'removeEmptyAttrs',
'removeHiddenElems',
'removeEmptyText',
'removeEmptyContainers',
// 'removeViewBox',
'cleanupEnableBackground',
'convertStyleToAttrs',
'convertColors',
'convertPathData',
'convertTransform',
'removeUnknownsAndDefaults',
'removeNonInheritableGroupAttrs',
'removeUselessStrokeAndFill',
'removeUnusedNS',
'cleanupIds',
'cleanupNumericValues',
'moveElemsAttrsToGroup',
'moveGroupAttrsToElems',
'collapseGroups',
// 'removeRasterImages',
'mergePaths',
'convertShapeToPath',
'sortAttrs',
'removeDimensions',
//{ name: 'removeAttrs', params: { attrs: '(stroke|fill)' } },
];
const directoryPath = 'dist/img';
const files = fs.readdirSync(directoryPath);
files.forEach(function (filepath) {
if (filepath.endsWith(".svg")) {
filepath = path.resolve(__dirname, "..", directoryPath, filepath);
console.log(filepath);
const data = fs.readFileSync(filepath, 'utf8');
const result = optimize(data, { path: filepath, plugins: plugins });
fs.writeFileSync(filepath, result.data);
}
});