Skip to content

Commit

Permalink
Merge pull request #7 from gapitio/refactor/update-to-v2-of-svgo
Browse files Browse the repository at this point in the history
Refactor/update to v2 of svgo
  • Loading branch information
porsager authored Mar 29, 2022
2 parents 2517569 + a3cf916 commit d920961
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 294 deletions.
19 changes: 5 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
const defaults = {
plugins: [{
removeViewBox: false
}, {
removeDimensions: true
}]
}

module.exports = function svg(options) {
const svgo = options && options.raw
? ({ optimize: x => Promise.resolve({ data: x }) })
: new (require('svgo'))(options || defaults)

module.exports = function svg(options, optimize) {
const optimize = optimize || require('svgo').optimize;
return {
name: 'svgo',
transform: (code, id) => {
if (id.endsWith('.svg')) {
return svgo.optimize(code, { path: id }).then(result => ({
const result = options?.raw ? { data: code } : optimize(code, { path: id, ...options })
return {
map: { mappings: '' },
code: 'export default ' + JSON.stringify(result.data)
}))
}
}
}
}
Expand Down
Loading

0 comments on commit d920961

Please sign in to comment.