mirror of
https://github.com/svg/svgo.git
synced 2026-01-27 07:02:06 +03:00
This is usually enough to prevent silly mistakes. Formatting will be done by prettier after merging pull requests.
67 lines
1.5 KiB
JavaScript
67 lines
1.5 KiB
JavaScript
'use strict';
|
|
|
|
const FS = require('fs');
|
|
const PATH = require('path');
|
|
const { optimize } = require('../lib/svgo');
|
|
const filepath = PATH.resolve(__dirname, 'test.svg');
|
|
const config = {
|
|
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', attrs: '(stroke|fill)'},
|
|
]
|
|
};
|
|
|
|
FS.readFile(filepath, 'utf8', function(err, data) {
|
|
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
|
|
const result = optimize(data, {path: filepath, ...config});
|
|
|
|
console.log(result);
|
|
|
|
// {
|
|
// // optimized SVG data string
|
|
// data: '<svg width="10" height="20">test</svg>'
|
|
// // additional info such as width/height
|
|
// info: {
|
|
// width: '10',
|
|
// height: '20'
|
|
// }
|
|
// }
|
|
|
|
});
|