mirror of
https://github.com/ionic-team/ionicons.git
synced 2026-11-30 16:48:16 +01:00
chore: SVG optimization no longer breaks outline icons (#1313)
This commit is contained in:
@@ -50,7 +50,7 @@ Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for informati
|
||||
|
||||
1. Run `npm start` from the root directory to start a local version of the icon test.
|
||||
2. Modify the icon test as needed in the `index.html` file.
|
||||
|
||||
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.
|
||||
|
||||
<!-- #### Building Changes
|
||||
|
||||
|
||||
+12
-8
@@ -51,6 +51,16 @@ async function optimizeSvgs(srcSvgData: SvgData[]) {
|
||||
if (!Array.isArray(params.attrs)) {
|
||||
params.attrs = [params.attrs];
|
||||
}
|
||||
|
||||
/**
|
||||
* All host SVG elements must have
|
||||
* the ionicons class otherwise styles
|
||||
* will not apply.
|
||||
*/
|
||||
if (item.elem === 'svg') {
|
||||
item.class.add('ionicon');
|
||||
}
|
||||
|
||||
if (item.isElem()) {
|
||||
item.eachAttr((attr) => {
|
||||
if (attr.name === 'fill') {
|
||||
@@ -165,14 +175,8 @@ async function optimizeSvg(
|
||||
const srcSvgContent = await fs.readFile(svgData.srcFilePath, 'utf8');
|
||||
|
||||
const optimizedSvg = await optimizePass.optimize(srcSvgContent, { path: svgData.srcFilePath });
|
||||
|
||||
const optimizedCode = optimizedSvg.data.replace(
|
||||
/<svg (.*?)>/,
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">`,
|
||||
);
|
||||
|
||||
const webComponentSvg = await webComponentPass.optimize(optimizedCode, { path: svgData.srcFilePath });
|
||||
const sourceSvg = await sourcePass.optimize(optimizedCode, { path: svgData.srcFilePath });
|
||||
const webComponentSvg = await webComponentPass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
|
||||
const sourceSvg = await sourcePass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
|
||||
|
||||
svgData.optimizedSvgContent = webComponentSvg.data;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user