-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: update dependencies and config (#31)
- update dependencies in package.json - fork svgo config from bootstrap
- Loading branch information
Showing
2 changed files
with
64 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,74 @@ | ||
'use strict' | ||
|
||
const { extendDefaultPlugins } = require('svgo') | ||
const path = require('path') | ||
|
||
module.exports = { | ||
multipass: true, | ||
js2svg: { | ||
pretty: true, | ||
indent: 2 | ||
indent: 2, | ||
eol: 'lf' | ||
}, | ||
plugins: extendDefaultPlugins([ | ||
plugins: [ | ||
{ | ||
name: 'cleanupListOfValues' | ||
name: 'preset-default', | ||
params: { | ||
overrides: { | ||
removeUnknownsAndDefaults: { | ||
keepRoleAttr: true | ||
}, | ||
removeViewBox: false | ||
} | ||
} | ||
}, | ||
// The next plugins are included in svgo but are not part of preset-default, | ||
// so we need to enable them separately | ||
'cleanupListOfValues', | ||
'sortAttrs', | ||
{ | ||
name: 'removeAttrs', | ||
params: { | ||
attrs: [ | ||
'clip-rule', | ||
'data-name', | ||
'fill', | ||
'clip-rule' | ||
'fill' | ||
] | ||
} | ||
}, | ||
// Custom plugin which resets the SVG attributes to explicit values | ||
{ | ||
name: 'removeUnknownsAndDefaults', | ||
name: 'explicitAttrs', | ||
type: 'visitor', | ||
params: { | ||
keepRoleAttr: true | ||
attributes: { | ||
xmlns: 'http://www.w3.org/2000/svg', | ||
width: '16', | ||
height: '16', | ||
fill: 'currentColor', | ||
class: '', // We replace the class with the correct one based on filename later | ||
viewBox: '0 0 16 16' | ||
} | ||
}, | ||
fn(_root, params, info) { | ||
if (!params.attributes) { | ||
return null | ||
} | ||
|
||
const basename = path.basename(info.path, '.svg') | ||
|
||
return { | ||
element: { | ||
enter(node, parentNode) { | ||
if (node.name === 'svg' && parentNode.type === 'root') { | ||
// We set the `svgAttributes` in the order we want to, | ||
// hence why we remove the attributes and add them back | ||
node.attributes = {} | ||
for (const [key, value] of Object.entries(params.attributes)) { | ||
node.attributes[key] = key === 'class' ? `qi qi-${basename}` : value | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
{ | ||
name: 'removeViewBox', | ||
active: false | ||
}, | ||
{ | ||
name: 'sortAttrs' | ||
} | ||
]) | ||
] | ||
} |