Skip to content

Commit

Permalink
update svgo
Browse files Browse the repository at this point in the history
  • Loading branch information
kamijin-fanta committed Nov 17, 2023
1 parent 399b45c commit 039502a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 114 deletions.
2 changes: 1 addition & 1 deletion packages/react-icons/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
| [Typicons](http://s-ings.com/typicons/) | [CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/) | 2.1.2 | 336 |
| [Github Octicons icons](https://octicons.github.com/) | [MIT](https://github.com/primer/octicons/blob/master/LICENSE) | 18.3.0 | 264 |
| [Feather](https://feathericons.com/) | [MIT](https://github.com/feathericons/feather/blob/master/LICENSE) | 4.29.1 | 287 |
| [Lucide](https://lucide.dev/) | [ISC](https://github.com/lucide-icons/lucide/blob/main/LICENSE) | v4.11.0-15-g7493227d | 1215 |
| [Lucide](https://lucide.dev/) | [ISC](https://github.com/lucide-icons/lucide/blob/main/LICENSE) | v4.12.0-2-g399b45c3 | 1215 |
| [Game Icons](https://game-icons.net/) | [CC BY 3.0](https://creativecommons.org/licenses/by/3.0/) | 12920d6565588f0512542a3cb0cdfd36a497f910 | 4040 |
| [Weather Icons](https://erikflowers.github.io/weather-icons/) | [SIL OFL 1.1](http://scripts.sil.org/OFL) | 2.0.12 | 219 |
| [Devicons](https://vorillaz.github.io/devicons/) | [MIT](https://opensource.org/licenses/MIT) | 1.8.0 | 192 |
Expand Down
2 changes: 1 addition & 1 deletion packages/react-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"lucide-static": "^0.263.0",
"p-queue": "^7.3.0",
"prettier": "^2.7.1",
"svgo": "^1.3.2",
"svgo": "^3.0.3",
"typescript": "^4.8.4"
},
"scripts": {
Expand Down
130 changes: 24 additions & 106 deletions packages/react-icons/scripts/svgo.ts
Original file line number Diff line number Diff line change
@@ -1,116 +1,34 @@
import SVGO from "svgo";
import {Config} from "svgo";

export const svgo = new SVGO({
export const svgoConfig: Config = {
plugins: [
{
cleanupAttrs: true,
},
{
removeDoctype: true,
},
{
removeXMLProcInst: true,
},
{
removeComments: true,
},
{
removeMetadata: true,
},
{
removeTitle: true,
},
{
removeDesc: true,
},
{
removeUselessDefs: true,
},
{
removeEditorsNSData: true,
},
{
removeEmptyAttrs: true,
},
{
removeHiddenElems: true,
},
{
removeEmptyText: true,
},
{
removeEmptyContainers: true,
},
{
removeViewBox: false,
},
{
cleanupEnableBackground: true,
},
{
convertStyleToAttrs: true,
},
{
convertColors: {
currentColor: true,
name: 'preset-default',
params: {
overrides: {
removeViewBox: false,
convertColors: {
currentColor: true,
}
},
},
},
{
convertPathData: true,
name: 'convertStyleToAttrs'
},
{
convertTransform: true,
name: 'removeDimensions'
},
{
removeUnknownsAndDefaults: true,
},
{
removeNonInheritableGroupAttrs: true,
},
{
removeUselessStrokeAndFill: true,
},
{
removeUnusedNS: true,
},
{
cleanupIDs: true,
},
{
cleanupNumericValues: true,
},
{
moveElemsAttrsToGroup: true,
},
{
moveGroupAttrsToElems: true,
},
{
collapseGroups: true,
},
{
removeRasterImages: false,
},
{
mergePaths: true,
},
{
convertShapeToPath: true,
},
{
sortAttrs: true,
},
{
removeDimensions: true,
},
{
removeAttributesBySelector: {
selector: "*:not(svg)",
attributes: ["stroke"],
{
name: 'removeAttributesBySelector',
params: {
selector: "*:not(svg)",
attributes: ["stroke"],
},
},
},
{
removeAttrs: { attrs: "data.*" },
},
],
});
{
name: 'removeAttrs',
params: { attrs: "data.*" },
},
]
}
5 changes: 3 additions & 2 deletions packages/react-icons/scripts/task_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import camelcase from "camelcase";
import { icons } from "../src/icons";
import { iconRowTemplate } from "./templates";
import { getIconFiles, convertIconData, rmDirRecursive } from "./logics";
import { svgo } from "./svgo";
import { svgoConfig } from "./svgo";
import { optimize as svgoOptimize } from "svgo";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
export async function dirInit({ DIST, LIB, rootDir }) {
Expand Down Expand Up @@ -65,7 +66,7 @@ export async function writeIconModule(icon, { DIST, LIB, rootDir }) {
for (const file of files) {
const svgStrRaw = await fs.readFile(file, "utf8");
const svgStr = content.processWithSVGO
? await svgo.optimize(svgStrRaw).then((result) => result.data)
? svgoOptimize(svgStrRaw, svgoConfig).data
: svgStrRaw;

const iconData = await convertIconData(svgStr, content.multiColor);
Expand Down
5 changes: 3 additions & 2 deletions packages/react-icons/scripts/task_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import camelcase from "camelcase";
import { icons } from "../src/icons";
import { iconRowTemplate } from "./templates";
import { getIconFiles, convertIconData, rmDirRecursive } from "./logics";
import { svgo } from "./svgo";
import { svgoConfig } from "./svgo";
import { optimize as svgoOptimize } from "svgo";
import { IconDefinition } from "./_types";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
Expand Down Expand Up @@ -49,7 +50,7 @@ export async function writeIconModuleFiles(
for (const file of files) {
const svgStrRaw = await fs.readFile(file, "utf8");
const svgStr = content.processWithSVGO
? await svgo.optimize(svgStrRaw).then((result) => result.data)
? await svgoOptimize(svgStrRaw, svgoConfig).data
: svgStrRaw;

const iconData = await convertIconData(svgStr, content.multiColor);
Expand Down
63 changes: 61 additions & 2 deletions yarn.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 039502a

Please sign in to comment.