jpskill.com
🎨 デザイン コミュニティ

svgo

SVGOは、SVGファイルの不要な情報を削除したり、パスを最適化したりして、ファイルサイズを小さくするSkill。アイコンシステムの構築や、デザインツールから出力されたSVGの整理、CI/CD環境での自動最適化に役立ちます。

📜 元の英語説明(参考)

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.

🇯🇵 日本人クリエイター向け解説

一言でいうと

SVGOは、SVGファイルの不要な情報を削除したり、パスを最適化したりして、ファイルサイズを小さくするSkill。アイコンシステムの構築や、デザインツールから出力されたSVGの整理、CI/CD環境での自動最適化に役立ちます。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o svgo.zip https://jpskill.com/download/15436.zip && unzip -o svgo.zip && rm svgo.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15436.zip -OutFile "$d\svgo.zip"; Expand-Archive "$d\svgo.zip" -DestinationPath $d -Force; ri "$d\svgo.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して svgo.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → svgo フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

SVGO

SVGオプティマイザーです。エディタのメタデータを削除し、グループを縮小し、パスを短縮し、見た目の変化なしに最小化します。

セットアップ

# SVGOをCLIツールおよびNode.jsライブラリとしてインストールします。
npm install -D svgo

CLI の使用法

# 単一のSVGファイルを最適化し、上書きします。
npx svgo input.svg -o output.svg

# ディレクトリ内のすべてのSVGを再帰的に最適化します。
npx svgo -r -f ./icons --output ./icons-optimized

# 書き込みせずに最適化の統計を表示します。
npx svgo input.svg --pretty --indent 2 -o -

プログラムによる API

// src/svg/optimize.ts — カスタム設定でSVG文字列をプログラムで最適化します。
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;
}

カスタムプラグインの設定

// svgo.config.js — プロジェクトレベルのSVGO設定。特定のSVGを壊すプラグインを無効にします
// (例:viewBoxを保持し、アイコン内のパスをマージしない)。
/** @type {import('svgo').Config} */
module.exports = {
  multipass: true,
  plugins: [
    {
      name: "preset-default",
      params: {
        overrides: {
          removeViewBox: false,        // レスポンシブスケーリングのためにviewBoxを保持
          mergePaths: false,           // マージしない — 一部のアイコンアニメーションを壊す
          convertShapeToPath: false,   // セマンティックな形状(rect、circle)を保持
        },
      },
    },
    "removeXMLNS",          // インラインSVGで使用するためにxmlnsを削除
    "removeDimensions",     // width/heightを削除し、viewBoxに依存
    "sortAttrs",
    "removeStyleElement",
  ],
};

バッチ処理

// src/svg/batch.ts — ディレクトリ内のすべてのSVGを最適化し、節約量を報告します。
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}%`);
}

カスタムプラグインの作成

// src/svg/custom-plugin.ts — すべての<path>要素にCSSスタイリング用のclass属性を追加するSVGOカスタムプラグイン。
import type { CustomPlugin } from "svgo";

export const addPathClass: CustomPlugin = {
  name: "addPathClass",
  fn: () => ({
    element: {
      enter: (node) => {
        if (node.name === "path") {
          node.attributes.class = "icon-path";
        }
      },
    },
  }),
};

// 使用法: optimize(svg, { plugins: [addPathClass] })

ビルド統合

// vite.config.ts — ビルド時にSVGを最適化するためにvite-plugin-svgoを使用します。
// コンポーネントとしてインポートされたSVGは自動的に最適化されます。
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",
      ],
    }),
  ],
});
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

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",
      ],
    }),
  ],
});