Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade svgo #43

Merged
merged 1 commit into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"dependencies": {
"is-svg": "^4.2.1",
"svgo": "^1.3.2"
"svgo": "^2.1.0"
},
"devDependencies": {
"ava": "^3.8.0",
Expand Down
9 changes: 5 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
])
})
]
});
Expand All @@ -43,7 +44,7 @@ Returns a `Promise<Buffer>`.

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

Expand Down
7 changes: 4 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const test = require('ava');
const imageminSvgo = require('.');
const {extendDefaultPlugins} = require('svgo');

test('optimize a SVG', async t => {
t.is((await imageminSvgo()('<svg><style> circle {} </style></svg>')).toString(), '<svg><style/></svg>');
});

test('support SVGO options', async t => {
const data = (await imageminSvgo({
plugins: [{
removeStyleElement: true
}]
plugins: extendDefaultPlugins([{
name: 'removeStyleElement'
}])
})('<svg><style> circle {} </style></svg>')).toString();

t.is(data, '<svg/>');
Expand Down