
SVGO
CLISVG 优化命令行工具与 Node.js 库:删除编辑器元数据、注释、隐藏元素和冗余属性来压缩 SVG,可递归处理整个目录,并通过插件配置精细控制优化规则。
SVGO

SVGO, short for SVG Optimizer, is a Node.js library and command-line application for optimizing SVG files.
💖 Sponsor SVGO on Open Collective to support continued improvements in stability and performance.
Why?
SVG files, especially those exported from vector editors, usually contain a lot of redundant information. This includes editor metadata, comments, hidden elements, default or suboptimal values, and other stuff that can be safely removed or converted without impacting rendering.
Installation
You can install SVGO globally through npm, yarn, or pnpm. Alternatively, drop the global flag (global/-g) to use it in your Node.js project.
# npm
npm install -g svgo
# yarn
yarn global add svgo
# pnpm
pnpm add -g svgo
Command-line usage
Process single files:
svgo one.svg two.svg -o one.min.svg two.min.svg
Process a directory of files recursively with -r/--recursive and -f/--folder:
svgo -rf path/to/directory_with_svgs -o path/to/output_directory
Help for advanced usage:
svgo --help
Configuration
SVGO has a plugin architecture. You can read more about all plugins in Plugins | SVGO Documentation, and the default plugins in Preset Default | SVGO Documentation.
SVGO reads the configuration from svgo.config.mjs or the --config path/to/config.mjs command-line option. Some other parameters can be configured though command-line options too.
svgo.config.mjs
export default {
multipass: false, // boolean
datauri: 'base64', // 'base64'|'enc'|'unenc'
js2svg: {
indent: 4, // number
pretty: false, // boolean
},
plugins: [
'preset-default', // built-in plugins enabled by default
'prefixIds', // enable built-in plugins by name
// enable built-in plugins with an object to configure plugins
{
name: 'prefixIds',
params: {
prefix: 'uwu',
},
},
],
};
Default preset
Instead of configuring SVGO from scratch, you can tweak the default preset to suit your needs by configuring or disabling the respective plugin.
svgo.config.mjs
export default {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
// disable a default plugin
cleanupIds: false,
// customize the params of a default plugin
inlineStyles: {
onlyMatchedOnce: false,
},
},
},
},
],
};
You can find a list of the default plugins in the order they run in Preset Default | SVGO Documentation.
Custom plugins
You can also specify custom plugins:
svgo.config.mjs
import importedPlugin from './imported-plugin';
export default {
plugins: [
// plugin imported from another JavaScript file
importedPlugin,
// plugin defined inline
{
name: 'customPlugin',
params: {
paramName: 'paramValue',
},
fn: (ast, params, info) => {},
},
],
};
API usage
SVGO provides a few low level utilities.
optimize
The core of SVGO is optimize function.
import { optimize } from 'svgo';
const result = optimize(svgString, {
path: 'path-to.svg', // recommended
multipass: true, // all other config fields are available here
});
const optimizedSvgString = result.data;
loadConfig
If you write a tool on top of SVGO you may want to resolve the svgo.config.mjs file.
import { loadConfig } from 'svgo';
const config = await loadConfig();
You can also specify a path and customize the current working directory.
const config = await loadConfig(configFile, cwd);
License and Copyright
This software is released under the terms of the MIT license.
Logo by André Castillo.
相關資源

pngquant
CLI有损 PNG 压缩命令行工具:把图片转成保留透明通道的 8 位 PNG,体积通常缩小 60%–80%,可整批压缩并设定质量区间,适合给公众号配图、课件插图和网页切图瘦身。macOS 可用 Homebrew 安装,无需账号。
kornelski/pngquant5.8k
VTracer
CLI把 JPG、PNG 等位图转成 SVG 矢量图的命令行工具,支持彩色描摹、黑白线稿和光照不均的扫描件,适合把 logo、插画和扫描的旧图纸矢量化。命令行版目前是 1.0 预览版,用 cargo 安装,需要 Rust 环境;也提供桌面版。
visioncortex/vtracer7.3k
fontTools
CLI字体处理工具集:pyftsubset 按实际用到的文字裁剪字体并输出 WOFF2,给中文网页字体瘦身;ttx 把字体转成可读写的 XML,便于查看和修改。适合让 agent 批量处理字体文件。需要 Python 3.11+,安装时带 woff 扩展才能输出 WOFF2;裁剪商用字体前先确认授权允许。
fonttools/fonttools5.3k
resvg
CLI高保真 SVG 渲染库与命令行工具,可把 SVG 图标、插画按指定尺寸导出为 PNG,适合批量切图;不依赖系统库,各平台渲染结果逐像素一致。不支持 SVG 动画,安装需要 Rust 环境(cargo),也可从 Releases 下载 macOS 预编译版。
linebender/resvg4.1k
glTF Transform
CLI读取、编辑与优化 glTF 2.0 3D 模型的 SDK 和命令行工具:optimize 一条命令批量优化,也可单独做 Draco、Meshopt 几何压缩与纹理缩放、WebP、KTX2 压缩,适合处理游戏与网页 3D 资产。
donmccurdy/glTF-Transform2k
GSAP AI Skills
SkillGSAP 官方动画技能合集:教 agent 正确使用核心 API、时间轴、ScrollTrigger 与各类插件,涵盖 React/Vue/Svelte 集成和动画性能优化。GreenSock 官方维护,所有插件均免费。
greensock/gsap-skills16.5k