svgo
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "svgo":https://skillpi.com/zh/skills/deepskill-091e2aa881ead34d71da1e577c13c274dbea985b935fd655a5eaa55aa6a48fcf。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
使用 SVGO 优化 SVG 文件。移除不必要的元数据、压缩路径、合并形状并配置插件,可将优化步骤集成到构建流程中。适用于需要减小 SVG 文件大小、清理从设计工具导出的 SVG、构建图标系统或在 CI/CD 中自动化 SVG 优化的场景。
介绍来源: third_party · TerminalSkills · 1.0.0 参考来源
SkillPi 解读
- 软件、账号及付费要求
- 贝什
- 实测状态
- 未测试
文件浏览
Frontmatter
name: svgo
description: >-
Optimize SVG files with SVGO — remove unnecessary metadata, minify paths,
merge shapes, configure plugins, and integrate into build pipelines. Use when
tasks involve reducing SVG file size, cleaning up exported SVGs from design
tools, building icon systems, or automating SVG optimization in CI/CD.
license: Apache-2.0
compatibility: "Node.js 14+"
metadata:
author: terminal-skills
version: "1.0.0"
category: design
tags: ["svg", "optimization", "icons", "minification", "build-tools"]SVGO
SVG Optimizer. Removes editor metadata, collapses groups, shortens paths, and minifies without visual changes.
Setup
# Install SVGO as a CLI tool and Node.js library.
npm install -D svgo
CLI Usage
# Optimize a single SVG file and overwrite it.
npx svgo input.svg -o output.svg
# Optimize all SVGs in a directory recursively.
npx svgo -r -f ./icons --output ./icons-optimized
# Show optimization stats without writing.
npx svgo input.svg --pretty --indent 2 -o -
Programmatic API
// src/svg/optimize.ts — Optimize SVG strings programmatically with custom config.
import { optimize, Config } from "svgo";
const config: Config = {
multipass: true,
plugins: [
"preset-default",
"removeDimensions",
{
name: "sortAttrs",
params: { xmlnsOrder: "alphabetical" },
},
],
};
export function optimizeSvg(svgString: string): string {
const result = optimize(svgString, config);
return result.data;
}
Custom Plugin Configuration
// svgo.config.js — Project-level SVGO config. Disable plugins that break
// specific SVGs (e.g., keep viewBox, don't merge paths in icons).
/** @type {import('svgo').Config} */
module.exports = {
multipass: true,
plugins: [
{
name: "preset-default",
params: {
overrides: {
removeViewBox: false, // keep viewBox for responsive scaling
mergePaths: false, // don't merge — breaks some icon animations
convertShapeToPath: false, // keep semantic shapes (rect, circle)
},
},
},
"removeXMLNS", // remove xmlns for inline SVG use
"removeDimensions", // remove width/height, rely on viewBox
"sortAttrs",
"removeStyleElement",
],
};
Batch Processing
// src/svg/batch.ts — Optimize all SVGs in a directory and report savings.
import { optimize } from "svgo";
import fs from "fs";
import path from "path";
export async function optimizeDirectory(inputDir: string, outputDir: string) {
const files = fs.readdirSync(inputDir).filter((f) => f.endsWith(".svg"));
let totalBefore = 0;
let totalAfter = 0;
fs.mkdirSync(outputDir, { recursive: true });
for (const file of files) {
const input = fs.readFileSync(path.join(inputDir, file), "utf-8");
const result = optimize(input, { multipass: true, plugins: ["preset-default"] });
totalBefore += input.length;
totalAfter += result.data.length;
fs.writeFileSync(path.join(outputDir, file), result.data);
}
const savings = ((1 - totalAfter / totalBefore) * 100).toFixed(1);
console.log(`Optimized ${files.length} files. Saved ${savings}%`);
}
Writing a Custom Plugin
// src/svg/custom-plugin.ts — SVGO custom plugin that adds a class attribute
// to all <path> elements for CSS styling.
import type { CustomPlugin } from "svgo";
export const addPathClass: CustomPlugin = {
name: "addPathClass",
fn: () => ({
element: {
enter: (node) => {
if (node.name === "path") {
node.attributes.class = "icon-path";
}
},
},
}),
};
// Usage: optimize(svg, { plugins: [addPathClass] })
Build Integration
// vite.config.ts — Use vite-plugin-svgo to optimize SVGs at build time.
// SVGs imported as components are automatically optimized.
import { defineConfig } from "vite";
import svgo from "vite-plugin-svgo";
export default defineConfig({
plugins: [
svgo({
multipass: true,
plugins: [
{ name: "preset-default", params: { overrides: { removeViewBox: false } } },
"removeDimensions",
],
}),
],
});当前收录版本
1.0.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- SVG 优化是前端开发和设计系统中的高频刚需任务,Skill 提供了从基础使用到高级集成的完整解决方案
- 覆盖 CLI、API、批量处理、自定义插件和构建工具集成,显著提升开发效率
亮点
- 触发描述精准覆盖减小文件大小、清理设计工具导出 SVG、构建图标系统、CI/CD 自动化等核心场景
- 边界清晰,不易与其他工具混淆
亮点
- 文档结构清晰,分阶段引导用户从安装到高级用法
- 每部分均配有端到端代码示例,frontmatter 完整规范
亮点
- 工具来源明确,参数配置合理,覆盖主要异常处理
- 批量处理和构建集成示例可靠,无明显执行漏洞
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
读取本地文件
限定到你选择的文件或项目目录;避免读取无关的个人资料、密钥和配置文件。
主文档提及 · 第 108 行 -
保存或修改文件
先确认输出目录和同名文件是否会被覆盖;重要文件保留备份,优先写入新的输出目录。
主文档提及 · 第 114 行 -
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 25, 32, 35, 38 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
贝什
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。