diff --git a/README.md b/README.md index c45b5fd6a..24d073ac0 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ SVGO logo - ## SVGO [![npm version](https://img.shields.io/npm/v/svgo)](https://npmjs.org/package/svgo) [![Discord](https://img.shields.io/discord/815166721315831868)](https://discord.gg/z8jX8NYxrE) **SVG O**ptimizer is a Node.js-based tool for optimizing SVG vector graphics files. @@ -53,8 +52,8 @@ module.exports = { js2svg: { indent: 2, // string with spaces or number of spaces. 4 by default pretty: true, // boolean, false by default - } -} + }, +}; ``` SVGO has a plugin-based architecture, so almost every optimization is a separate plugin. @@ -67,97 +66,83 @@ module.exports = { 'builtinPluginName', // or by expanded version { - name: 'builtinPluginName' + name: 'builtinPluginName', }, // some plugins allow/require to pass options { name: 'builtinPluginName', params: { - optionName: 'optionValue' - } - } - ] -} + optionName: 'optionValue', + }, + }, + ], +}; ``` -The default list is fully overridden if the `plugins` field is specified. To extend the default -list use the `extendDefaultPlugins` utility: +The default preset of plugins is fully overridden if the `plugins` field is specified. +Use `preset-default` plugin to customize plugins options. ```js -const { extendDefaultPlugins } = require('svgo'); module.exports = { - plugins: extendDefaultPlugins([ + plugins: [ { - name: 'builtinPluginName', + name: 'preset-default', params: { - optionName: 'optionValue' - } - } - ]) -} -``` - -To disable one of the default plugins use the `active` field: - -```js -const { extendDefaultPlugins } = require('svgo'); -module.exports = { - plugins: extendDefaultPlugins([ - { - name: 'builtinPluginName', - active: false - } - ]) -} + overrides: { + // customize options + builtinPluginName: { + optionName: 'optionValue', + }, + // or disable plugins + anotherBuiltinPlugin: false, + }, + }, + }, + ], +}; ``` -See the list of the default plugins: - -```js -module.exports = { - plugins: [ - 'removeDoctype', - 'removeXMLProcInst', - 'removeComments', - 'removeMetadata', - 'removeEditorsNSData', - 'cleanupAttrs', - 'mergeStyles', - 'inlineStyles', - 'minifyStyles', - 'cleanupIDs', - 'removeUselessDefs', - 'cleanupNumericValues', - 'convertColors', - 'removeUnknownsAndDefaults', - 'removeNonInheritableGroupAttrs', - 'removeUselessStrokeAndFill', - 'removeViewBox', - 'cleanupEnableBackground', - 'removeHiddenElems', - 'removeEmptyText', - 'convertShapeToPath', - 'convertEllipseToCircle', - 'moveElemsAttrsToGroup', - 'moveGroupAttrsToElems', - 'collapseGroups', - 'convertPathData', - 'convertTransform', - 'removeEmptyAttrs', - 'removeEmptyContainers', - 'mergePaths', - 'removeUnusedNS', - 'sortDefsChildren', - 'removeTitle', - 'removeDesc' - ] -} -``` +Default preset includes the following list of plugins: + +- removeDoctype +- removeXMLProcInst +- removeComments +- removeMetadata +- removeEditorsNSData +- cleanupAttrs +- mergeStyles +- inlineStyles +- minifyStyles +- cleanupIDs +- removeUselessDefs +- cleanupNumericValues +- convertColors +- removeUnknownsAndDefaults +- removeNonInheritableGroupAttrs +- removeUselessStrokeAndFill +- removeViewBox +- cleanupEnableBackground +- removeHiddenElems +- removeEmptyText +- convertShapeToPath +- convertEllipseToCircle +- moveElemsAttrsToGroup +- moveGroupAttrsToElems +- collapseGroups +- convertPathData +- convertTransform +- removeEmptyAttrs +- removeEmptyContainers +- mergePaths +- removeUnusedNS +- sortDefsChildren +- removeTitle +- removeDesc It's also possible to specify a custom plugin: ```js -const anotherCustomPlugin = require('./another-custom-plugin.js') +const anotherCustomPlugin = require('./another-custom-plugin.js'); module.exports = { plugins: [ { @@ -166,11 +151,11 @@ module.exports = { params: { optionName: 'optionValue', }, - fn: (ast, params, info) => {} + fn: (ast, params, info) => {}, }, - anotherCustomPlugin - ] -} + anotherCustomPlugin, + ], +}; ``` ## API usage @@ -187,9 +172,9 @@ const result = optimize(svgString, { // optional but recommended field path: 'path-to.svg', // all config fields are also available here - multipass: true -}) -const optimizedSvgString = result.data + multipass: true, +}); +const optimizedSvgString = result.data; ``` ### loadConfig @@ -198,95 +183,95 @@ If you write a tool on top of SVGO you might need a way to load SVGO config. ```js const { loadConfig } = require('svgo'); -const config = await loadConfig() +const config = await loadConfig(); // you can also specify a relative or absolute path and customize the current working directory -const config = await loadConfig(configFile, cwd) +const config = await loadConfig(configFile, cwd); ``` ## Built-in plugins -| Plugin | Description | Default | -| ------ | ----------- | ------- | -| [cleanupAttrs](https://github.com/svg/svgo/blob/master/plugins/cleanupAttrs.js) | cleanup attributes from newlines, trailing, and repeating spaces | `enabled` | -| [mergeStyles](https://github.com/svg/svgo/blob/master/plugins/mergeStyles.js) | merge multiple style elements into one | `enabled` | -| [inlineStyles](https://github.com/svg/svgo/blob/master/plugins/inlineStyles.js) | move and merge styles from `