Skip to content

Commit c9552b6

Browse files
author
Cole Bemis
authored
fix: Remove unecessary whitespace from SVG contents
```js /* BEFORE */ { circle: "\n <circle cx=\"12\" cy=\"12\" r=\"10\"></circle>\n" } /* AFTER */ { circle: "<circle cx=\"12\" cy=\"12\" r=\"10\"></circle>" } ```
1 parent b814a2b commit c9552b6

4 files changed

Lines changed: 115 additions & 3 deletions

File tree

bin/__tests__/build-icons-object.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import buildIconsObject from '../build-icons-object';
33

44
const SVG_FILES = {
55
'icon1.svg':
6-
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="23" y1="1" x2="1" y2="23" /><line x1="1" y1="1" x2="23" y2="23" /></svg>',
6+
'<svg\n xmlns="http://www.w3.org/2000/svg"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n>\n <line x1="23" y1="1" x2="1" y2="23" />\n <line x1="1" y1="1" x2="23" y2="23" />\n</svg>',
77
'icon2.svg':
8-
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="11" /></svg>',
8+
'<svg\n xmlns="http://www.w3.org/2000/svg"\n width="24"\n height="24"\n viewBox="0 0 24 24"\n>\n <circle cx="12" cy="12" r="11" />\n</svg>',
99
};
1010

1111
function getSvg(svgFile) {

bin/build-icons-object.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable import/no-extraneous-dependencies */
22
import path from 'path';
33
import cheerio from 'cheerio';
4+
import { minify } from 'html-minifier';
45

56
/**
67
* Build an object in the format: `{ <name>: <contents> }`.
@@ -28,7 +29,7 @@ function buildIconsObject(svgFiles, getSvg) {
2829
*/
2930
function getSvgContents(svg) {
3031
const $ = cheerio.load(svg);
31-
return $('svg').html();
32+
return minify($('svg').html(), { collapseWhitespace: true });
3233
}
3334

3435
export default buildIconsObject;

package-lock.json

Lines changed: 110 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"eslint": "^4.0.0",
3232
"eslint-config-airbnb-base": "^11.2.0",
3333
"eslint-plugin-import": "^2.5.0",
34+
"html-minifier": "^3.5.6",
3435
"husky": "^0.13.4",
3536
"jest": "^21.2.1",
3637
"npm-run-all": "^4.1.2",

0 commit comments

Comments
 (0)