Permalink
Browse files

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>" }
```
  • Loading branch information...
colebemis committed Nov 20, 2017
1 parent b814a2b commit c9552b69161d12f67d43b463956805f6420f09f4
Showing with 115 additions and 3 deletions.
  1. +2 −2 bin/__tests__/build-icons-object.test.js
  2. +2 −1 bin/build-icons-object.js
  3. +110 −0 package-lock.json
  4. +1 −0 package.json
@@ -3,9 +3,9 @@ import buildIconsObject from '../build-icons-object';
const SVG_FILES = {
'icon1.svg':
'<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>',
'<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>',
'icon2.svg':
'<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>',
'<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>',
};
function getSvg(svgFile) {
@@ -1,6 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import cheerio from 'cheerio';
import { minify } from 'html-minifier';
/**
* Build an object in the format: `{ <name>: <contents> }`.
@@ -28,7 +29,7 @@ function buildIconsObject(svgFiles, getSvg) {
*/
function getSvgContents(svg) {
const $ = cheerio.load(svg);
return $('svg').html();
return minify($('svg').html(), { collapseWhitespace: true });
}
export default buildIconsObject;
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -31,6 +31,7 @@
"eslint": "^4.0.0",
"eslint-config-airbnb-base": "^11.2.0",
"eslint-plugin-import": "^2.5.0",
"html-minifier": "^3.5.6",
"husky": "^0.13.4",
"jest": "^21.2.1",
"npm-run-all": "^4.1.2",

0 comments on commit c9552b6

Please sign in to comment.