diff --git a/index.js b/index.js index 4204fd8..50096b2 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ 'use strict'; const isSvg = require('is-svg'); -const SVGO = require('svgo'); +const {optimize} = require('svgo'); module.exports = options => async buffer => { options = {multipass: true, ...options}; @@ -13,7 +13,6 @@ module.exports = options => async buffer => { buffer = buffer.toString(); } - const svgo = new SVGO(options); - const {data} = await svgo.optimize(buffer); + const {data} = optimize(buffer, options); return Buffer.from(data); }; diff --git a/package.json b/package.json index af67d60..95643fd 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ ], "dependencies": { "is-svg": "^4.2.1", - "svgo": "^1.3.2" + "svgo": "^2.1.0" }, "devDependencies": { "ava": "^3.8.0", diff --git a/readme.md b/readme.md index c11a50e..c605ee7 100644 --- a/readme.md +++ b/readme.md @@ -15,15 +15,16 @@ $ npm install imagemin-svgo ```js const imagemin = require('imagemin'); const imageminSvgo = require('imagemin-svgo'); +const {extendDefaultPlugins} = require('svgo'); (async () => { await imagemin(['images/*.svg'], { destination: 'build/images', plugins: [ imageminSvgo({ - plugins: [ - {removeViewBox: false} - ] + plugins: extendDefaultPlugins([ + {name: 'removeViewBox', active: false} + ]) }) ] }); @@ -43,7 +44,7 @@ Returns a `Promise`. Type: `Object` -Pass options to [SVGO](https://github.com/svg/svgo#what-it-can-do). +Pass options to [SVGO](https://github.com/svg/svgo#configuration). #### buffer diff --git a/test.js b/test.js index f578747..dfa4b83 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,6 @@ const test = require('ava'); const imageminSvgo = require('.'); +const {extendDefaultPlugins} = require('svgo'); test('optimize a SVG', async t => { t.is((await imageminSvgo()('')).toString(), ''); @@ -7,9 +8,9 @@ test('optimize a SVG', async t => { test('support SVGO options', async t => { const data = (await imageminSvgo({ - plugins: [{ - removeStyleElement: true - }] + plugins: extendDefaultPlugins([{ + name: 'removeStyleElement' + }]) })('')).toString(); t.is(data, '');