-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean-svg.js
32 lines (27 loc) · 855 Bytes
/
clean-svg.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
var fs = require('fs');
var _ = require('lodash');
var SVGO = require('svgo');
var svgo = new SVGO({
plugins: [
// remove width and height so svg can be responsive using viewBox
{removeDimensions: true}
]
});
var spritesDir = './assets/sprite';
var outDir = './src/app/svg';
var filenames = fs.readdirSync(spritesDir);
filenames.forEach((filename) => {
fs.readFile(`${spritesDir}/${filename}`, 'utf8', (err, data) => {
if(err) throw err;
// optimize svg file in sprite directory...
const outPath = `${outDir}/${filename.replace('mrdario_','')}`;
svgo.optimize(data, (optimized) => {
console.log(`optimized ${filename}`);
// ...and save to output directory
fs.writeFile(outPath, optimized.data, (err) => {
if(err) throw err;
console.log(`saved ${outPath}`);
});
});
});
});