Skip to content

Commit 64bbbf9

Browse files
authored
chore: SVG optimization no longer breaks outline icons (#1313)
1 parent c7f561c commit 64bbbf9

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

.github/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for informati
5050

5151
1. Run `npm start` from the root directory to start a local version of the icon test.
5252
2. Modify the icon test as needed in the `index.html` file.
53-
53+
3. If you are modifying icons, you can run `npm run build.files` to re-run the SVG optimization script to verify there are no changes after optimizing the SVG.
5454

5555
<!-- #### Building Changes
5656

scripts/build.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ async function optimizeSvgs(srcSvgData: SvgData[]) {
5151
if (!Array.isArray(params.attrs)) {
5252
params.attrs = [params.attrs];
5353
}
54+
55+
/**
56+
* All host SVG elements must have
57+
* the ionicons class otherwise styles
58+
* will not apply.
59+
*/
60+
if (item.elem === 'svg') {
61+
item.class.add('ionicon');
62+
}
63+
5464
if (item.isElem()) {
5565
item.eachAttr((attr) => {
5666
if (attr.name === 'fill') {
@@ -165,14 +175,8 @@ async function optimizeSvg(
165175
const srcSvgContent = await fs.readFile(svgData.srcFilePath, 'utf8');
166176

167177
const optimizedSvg = await optimizePass.optimize(srcSvgContent, { path: svgData.srcFilePath });
168-
169-
const optimizedCode = optimizedSvg.data.replace(
170-
/<svg (.*?)>/,
171-
`<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">`,
172-
);
173-
174-
const webComponentSvg = await webComponentPass.optimize(optimizedCode, { path: svgData.srcFilePath });
175-
const sourceSvg = await sourcePass.optimize(optimizedCode, { path: svgData.srcFilePath });
178+
const webComponentSvg = await webComponentPass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
179+
const sourceSvg = await sourcePass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
176180

177181
svgData.optimizedSvgContent = webComponentSvg.data;
178182

0 commit comments

Comments
 (0)