Skip to content

Commit

Permalink
Use non-deprecated SVGO options in HTMLNanoOptimizer
Browse files Browse the repository at this point in the history
(Hopefully) fixes #6744
  • Loading branch information
shish committed Sep 11, 2021
1 parent 9aa20cf commit ca261e8
Show file tree
Hide file tree
Showing 3 changed files with 206 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/optimizers/htmlnano/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"dependencies": {
"@parcel/plugin": "2.0.0-rc.0",
"htmlnano": "^1.0.0",
"htmlnano": "^1.0.1",
"nullthrows": "^1.1.1",
"posthtml": "^0.16.4",
"svgo": "^2.4.0"
Expand Down
55 changes: 20 additions & 35 deletions packages/optimizers/htmlnano/src/HTMLNanoOptimizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {Optimizer} from '@parcel/plugin';
import posthtml from 'posthtml';
import path from 'path';
import {SVG_ATTRS, SVG_TAG_NAMES} from './svgMappings';
// $FlowFixMe
import {extendDefaultPlugins} from 'svgo';

export default (new Optimizer({
async loadConfig({config, options}) {
Expand Down Expand Up @@ -57,44 +55,31 @@ export default (new Optimizer({
const htmlNanoConfig = {
minifyJs: false,
minifySvg: {
plugins: extendDefaultPlugins([
// Copied from htmlnano defaults.
plugins: [
{
name: 'collapseGroups',
active: false,
},
{
name: 'convertShapeToPath',
active: false,
},
// Additional defaults to preserve accessibility information.
{
name: 'removeTitle',
active: false,
},
{
name: 'removeDesc',
active: false,
},
{
name: 'removeUnknownsAndDefaults',
name: 'preset-default',
params: {
keepAriaAttrs: true,
keepRoleAttr: true,
overrides: {
// Copied from htmlnano defaults.
collapseGroups: false,
convertShapeToPath: false,
// Additional defaults to preserve accessibility information.
removeTitle: false,
removeDesc: false,
removeUnknownsAndDefaults: {
keepAriaAttrs: true,
keepRoleAttr: true,
},
// Do not minify ids or remove unreferenced elements in
// inline SVGs because they could actually be referenced
// by a separate inline SVG.
cleanupIDs: false,
},
},
},
// Do not minify ids or remove unreferenced elements in inline SVGs
// because they could actually be referenced by a separate inline SVG.
{
name: 'cleanupIDs',
active: false,
},
// XML namespaces are not required in HTML.
{
name: 'removeXMLNS',
active: true,
},
]),
'removeXMLNS',
],
},
...(preset || {}),
...clonedConfig,
Expand Down
Loading

0 comments on commit ca261e8

Please sign in to comment.